Commit Graph

56 Commits

Author SHA1 Message Date
Alex Dunn 9b85475fe4 add new setting to suppress join/leave announcements 2020-06-03 19:47:57 -07:00
Zorchenhimer c32838def6 Rework settings mutex and saving settings
- Move mutex into Settings struct
- Replace sync.Mutex with a sync.RWMutex
- Move adding approved emotes into a Settings method
- Save settings after adding emotes
- Wrap saving in a lock
2020-01-30 14:32:46 -05:00
Zorchenhimer 7feb277a33 Don't allow names that are the access pin
If a user tries to enter the pin as their name return an error instead
of accepting the name.
2019-11-30 10:27:06 -05:00
Zorchenhimer a85c618e4a Use better name error; Tweak name requirements
- "Invalid name" was replaced with a description of a valid name.
  Fixes #100
- Tweaked the valid name regex to require at least one number or letter.
2019-11-28 20:06:15 -05:00
Zorchenhimer a73375f152 Fix emotes
This reworks how emotes are cached in relation to their physical
location on disk.  Functionally, they should be the same from the user
perspective but it sets up some stuff that will make it easier to add
emotes from various sources.
2019-06-18 22:13:53 -04:00
joeyak 7962fad02e commiting so zorch can do my work 2019-06-01 19:41:28 -04:00
Zorchenhimer 607e61234c Add some more stats
Added a few more stats to keep track of:
- Max users in chat
- Stream start

Also added a `/stats` command to list the user count (current and max),
as well as uptime (sever and stream, separately).

Resolves #85
2019-04-14 00:25:49 -04:00
Zorchenhimer d513fe872d Remove temp connections
Temp connections were removed to reduce some complexity.  Now a
connection is a full client, even before joining chat.  A name is
required to be set to join chat and receive messages.

This change also removes the need for UUIDs on connections and clients.
2019-04-13 15:56:49 -04:00
joeyak ad2579d59a Adding some hardening to user joining
Client sends the server a object to join instead of a message
server can send a message to notify the user

closes #57
2019-04-13 13:12:08 -04:00
Zorchenhimer 5508dc3f1c Return errors from commands
Change the function signature for commands to return a string as well as
an error.  Currently, errors are handled no differently than normal
response messages.

Also removed the redundant `/setpin` command.
2019-04-11 21:10:04 -04:00
joeyak 791df37030 Update client emotes list on reload emotes
closes #75
2019-03-31 17:33:03 -04:00
Zorchenhimer 9c559c3818 Revert "Merge branch 'server-shutdown'"
This reverts commit 13d74faf01, reversing
changes made to ec0c6752bc.

These changes completely broke the RTMP stream.  Reverting until I
figure out why.
2019-03-31 00:07:19 -04:00
Zorchenhimer 13d74faf01 Merge branch 'server-shutdown' 2019-03-30 16:22:21 -04:00
Zorchenhimer 67b3143893 Add rate limiting
This should fix #65, although it may be expanded in the future.

Default settings for limits can be changed or disabled in the settings.
Default values:
- Chat: 1 second
- Duplicate chat: 30 seconds
- /nick: 5 minutes
- /auth: 5 seconds
- /color: 1 minute

Creation of the chat Client object has been moved from ChatRoom.Join()
to NewClient().  This function also handles setting the initial name.
2019-03-30 15:40:37 -04:00
joeyak ca72dc28c0 Add autocomplete for emotes
closes #9
2019-03-30 15:23:54 -04:00
Zorchenhimer e879112b1b Add some comments clarifying some things 2019-03-28 10:18:17 -04:00
Zorchenhimer 9bcbad6a07 Expand graceful shutdown to use http.Shutdown()
Not sure if this is better or not, but I'm testing it out.
2019-03-28 10:06:18 -04:00
joeyak 86207ecd48 Added spoilers in chat
If a user clicks the spoiler, it will change color and the background will revert.
closes #62
2019-03-24 23:43:30 -04:00
joeyak d419f64379 goimports found a line with an extra tab 2019-03-24 20:09:55 -04:00
Zorchenhimer fdbf39f00c Add some logging
Functions added:
- LogErrorf()
- LogErrorln()
- LogChatf()
- LogChatln()
- LogInfof()
- LogInfoln()
- LogDebugf()
- LogDebugln()
- LogDevf()
- LogDevln()

New settings configure the logging: LogLevel and LogFile.  LogLevel can
be set to one of: error, chat, info, or debug and will default to
error.  LogFile is an optional file to write to.  Providing a file will
not prevent output in the console.

LogDevf() and LogDevln() only compile when the "dev" flag passed to
build.  This will cause Travis-CI to fail the build if it finds any
calls to either function.
2019-03-24 18:58:59 -04:00
joeyak cd34480bba Change auth level checking to be on command level
The server sends new auth level to user when modded
closes #60
2019-03-24 17:27:04 -04:00
joeyak 5c87d70d3e Change unlock to be consistant with the message break if 2019-03-24 17:12:04 -04:00
Zorchenhimer 60f3ade2ee Fix clientsMtx lock without unlock in Broadcast()
Reorganize the lock/unlock pairs to be more consistent and to fix a
case with an uneven lock/unlock.
2019-03-24 16:38:42 -04:00
Zorchenhimer 2f252d5ae8 Strip @ prefix on names in commands
Names can be passed to commands with @ prefixed to them.

When forcing a color change on another user the @ explicitly defines
the name, instead of simply being stripped off.  This will allow the
a user named "red" to have their color changed: `/color @red blue`

A bunch of the color command code has changed with this to make things
less ambiguous and to add some other checks.  `/color red #FF0000` and
`/color @red red` will change the color of the user "red" to the color
red while `/color red red`will return with an error.  Note that the
color an name arguments can be in any order.

Resolves #64
2019-03-24 15:16:01 -04:00
Zorchenhimer 87f8839a33 Only send Chat and Event messages to temp clients
These should be the only messages that need to be sent to temp clients
for now.
2019-03-23 23:27:56 -04:00
Zorchenhimer 07589e7099 Don't allow banning admins 2019-03-23 18:09:27 -04:00
Zorchenhimer d734ec110e Remove error'd temp connections
If there's an error writing to a temp connection, remove it from the
chatroom.
2019-03-23 16:54:05 -04:00
Zorchenhimer 6ef0d6f1a5 Add some debugging info to the client connection 2019-03-23 16:10:04 -04:00
Zorchenhimer 62afc2eef9 Fixup ChatRoom.Broadcast()
Use an RW Mutex for chatConnection and use some goroutines when sending
data to clients in Broadcast().  This should prevent blocking on
unresponsive clients.
2019-03-23 14:50:47 -04:00
Zorchenhimer 0036dde265 Fix some typos
BroadCast() -> Broadcast()
startRmptServer() -> startRmtpServer()
2019-03-23 14:46:49 -04:00
joeyak bc983d9ce3 Removing unused variables and increasing queue
The UsernameMaxLength and MinLength constants were removed because common.IsValidUsername checks that.
Changed queue sizes to 1000 because if 25 people are joined and 4 say a message at the same time
it results in 100 messages.
2019-03-21 16:05:14 -04:00
joeyak 355f09bd48 Refactoring of ChatData
The processing of ChatData was changed so ChatData has a DataInterface object, which will be converted to a
ChatDataJSON that will have the DataInterface field converted to a json.RawMessage field. This change allows
greater customizability in the chat messages, since the Data field can still be read and modified.
2019-03-21 08:47:40 -04:00
Zorchenhimer 990060fb31 Fix removing clients from the clients map
ChatRoom.delClient() wasn't updated to use UUID's instead of names.
The calling functions were passing in a name instead of a suid, so
attempting to delete the client silently failed.

Fixes #52
2019-03-20 20:41:11 -04:00
joeyak 1cfa040f7b Added color names as possible arguements for /color
Did some linting fixing too.
Closes #45
2019-03-19 22:56:01 -04:00
Zorchenhimer 49e997c5ff Move some stuff to MovieNight.common
Moved to common/utils.go:
- IsValidName() (function replaces direct calls to regexp.MatchString())
- RandomColor()

Moved to common/emotes.go:
- LoadEmotes()
2019-03-19 17:25:49 -04:00
Zorchenhimer 1c6c23da3e Add /nick command
Using this command will change the current user's nickname in chat.
It has an alias of /name.

An admin can force a name change by supplying the current name and a new
name.  If a name has been changed by an admin, that user can no longer
change their name (similar to forced color change).

Resolves #42
2019-03-19 17:13:20 -04:00
Zorchenhimer 7dff29b152 Add user badges
Add badges for admins and mods.  Admins get a red badge, and mods get a
green one.

Normal users do not get a badge.
2019-03-16 18:11:27 -04:00
Zorchenhimer 75946b600b Move clients mutex lock in ChatRoom.Broadcast()
Don't lock the clients map while sleeping in ChatRoom.Broadcast().
2019-03-16 14:09:58 -04:00
Zorchenhimer f18b790c4d Wrap connection reads and writes with a mutex
Wrapping the connection with a mutex prevents the "concurrent write to
websocket connection" panic.  The new functions are ReadData() and
WriteData so as to not collide with ReadJSON() and WriteJSON().
2019-03-16 13:44:18 -04:00
joeyak bc90744798 Move broadcast logic to be self contained in the function 2019-03-15 18:57:50 -04:00
joeyak a717c6ef38 Converting from conn.WriteMessage to conn.WriteJson
This takes away some of the work on the developers side to worry about parsing the object as a json string.
Backend work for issue #7
2019-03-15 17:28:29 -04:00
Zorchenhimer 28d43a726a Add Mod notice messages
These messages are only sent to mods and admins for certain events:
- User gains mod/admin privileges
- User attempts to gain mod/admin privileges unsuccessfully
- Mod/Admin uses the /sv command
- Mod/Admin uses the /playing command
- Mod unmods themselves
- Mod/Admin mods/unmods a user
- Mod/Admin uses the /reloademotes command
- Mod/Admin uses the /reloadplayer command

A separate message queue is used for these messages, and they are only
sent to clients that are either a mod or an admin.  They are sent
with the same call to ChatRoom.Broadcast(), but after all the normal
messages are sent.

Resolves #3
2019-03-15 16:03:31 -04:00
joeyak 678ccab95c Add some backend infrastructure
The server can now send the client objects with data for the client to process.
issue #7
2019-03-15 02:19:16 -04:00
joeyak 6a2cb3f906 Fix some linting errors with error messages 2019-03-14 15:19:36 -04:00
Zorchenhimer 0effbf49b5 Rewrite ChatRoom.Broadcast()
The broadcast code would lock up eventually after a lot of messages.
It was rewritten to simplify and make it a bit more robust.  Chat
should no longer seize up for individual chatters or the entire room
after a lot of messages.
2019-03-14 10:11:14 -04:00
joeyak 2ef3684c14 Some linting fixes for the common package 2019-03-13 21:24:14 -04:00
joeyak 18465c61f5 Make the chatroom send each message individually
closes #24
2019-03-13 21:14:43 -04:00
Zorchenhimer 1cd490b04a Add single-use mod passwords
Single-use moderator passwords can only be generated by an admin with
the /modpass command.  To redeem the password and gain moderator
privileges, a user just needs to call /auth with the password.

The passwords are generated using the same function as the admin
password.  Additionally, generating passwords now uses crypto/rand
instead of math/rand.

Resolves #15
2019-03-13 16:51:07 -04:00
joeyak 5516313c79 Allow chat to be sent before the name is sent to the server
closes #17
2019-03-13 16:47:19 -04:00
Zorchenhimer a555e626af Merge branch 'json-communication'
# Conflicts:
#	chatclient.go
#	chatroom.go
2019-03-13 14:00:13 -04:00