Skip to content

Rewrite Chat module #4

@RedFlames

Description

@RedFlames

Just gonna use this for taking notes.

[Edit:] Initial conclusions after looking through most of the non-cmds ChatModule code, actually ChatModule isn't all that big? Tbh I wonder if it would be possible to pull "Chat" and "Commands" apart into two Modules and then rewrite those separately :widegladeline:

ideas/plans

  • I still have that really old chat module rewrite I could revive
  • Snip want to put an external lock around BroadcastRawCMD calls to prevent ws message race conditions
  • include message types to stop classifying by colors
  • might as well plan for client-local chatting with this rewrite too
  • introduce more fine-grained spam-controls, like to allow rapid "/tp" and "/e" usage
  • Make a /tp that doesn't send any session data and just goes to same room in same map (...could possibly be local??)
  • make a /del moderation-command and prefix the last N (30ish?) messages in client chat log with numbers that cycle through; actually make range of numbers 2N so that if you want to delete oldest deletable you don't accidentally delete a brand new message? -> And only show these numbers when /del is typed in; actually just use make completion prompts
  • should it be possible to fully hide global chat? Must be blocked from participating in it too. Implementation could be linked with a "forced" mode for moderation mutes or something.
  • (Fix code duplication in Prevent broadcasting targeted broadcasts to everyone 0x0ade/CelesteNet#113) Maybe ForceSend should be renamed to just be Send and have a boolean parameter with a default value for "forcing", whatever that means (Version increment and Action invoke thingy)

Thoughts about breaking changes:

I'm wondering if we'll need to keep some minimal implementations of "legacy" (i.e. current) chat message structures around. For when new clients might be connected to old servers and still need to at least accept old chat messages?
And new server chat should probably still at the very least detect old style clients and send them motd or an upgrade notice 🤷
Idk how a chat "protocol" upgrade would go down

Existing ChatModule etc.

related DataTypes

DataChat

  • fields:
    • DataPlayerInfo? Player
    • uint ID = 0xffffff
    • byte Version = 0
    • string Tag = ""
    • string Text = ""
    • Color Color = Color.White
    • DateTime Date = DateTime.UtcNow
    • DateTime ReceivedDate = DateTime.UtcNow
  • Written to transport:
    • (OptRef) Player
    • (uint) Version & ID packed into one value
    • (string) Tag
    • (string) Text
    • (Color, 3 bytes) Color
    • (Date in binary = 64-bit integer) Date
  • Read of the DataType sets CreatedByServer = false and ReceivedDate = DateTime.UtcNow
  • Filters on Handle & Send for dropping when Text.IsNullOrEmpty()
  • Server-only fields:
    • bool CreatedByServer
    • DataPlayerInfo[]? Targets
    • DataPlayerInfo? Target (is a property based on Targets)

Where does DataChat show up

  • ChatModule:
    • Handle( ... DataEmote) creates a DataChat purely for the PrepareAndLog, logging emotes
    • Broadcast(...) as called by /bc in-game and chat/chatx wscmd's, plus join/leave messages if enabled
    • SendTo(...) as called by
      • ChatCMDEnv.Send used to send all the command server responses
      • MOTD, Spam-error, WSCMDDissolve
    • passed into PrepareAndLog by running /cc, /gc and /w (=/r)
  • FrontendModule:
    • ...
  • Client:
    • ...

DataCommandList

  • ...

ChatModule

image

Pretty small besides the Command stuff

image

ChatModule methods

  • Init()
    • instantiate SpamContext
    • instantiate ChatCommands
    • add OnSessionStart to Server's OnSessionStart delegate/event
    • (add OnSessionEnd to existing sessions, I guess on the mythical hot-reload)
  • Dispose() -- basically opposite of Init()
  • OnSessionStart(...)
    • broadcast "join" message if enabled
    • send MOTD to joining session
    • send CommandList
    • set up SpamContext stuff with error-sender
    • add OnSessionEnd to the session.OnEnd
  • OnSessionEnd(...)
    • broadcast "leave" message if enabled
    • undo spam setup stuff
  • PrepareAndLog(...)
    • TODO: does a bunch of funny stuff lol
    • called from:
      • DataChat handler here in the module
      • for logging DataEmote as if they were chat if enabled
      • SendTo, see above under DataChat section
      • /gc, /cc and /w to create the corresponding chat messages
  • Handle(... DataChat)
    • TODO: Does a bunch of stuff lol
  • Handle(... DataEmote)
    • just handled here for the logging part 🤷
  • Broadcast(...)
    • see also above under DataChat sections
    • just creates a "server" DataChat message and shoves it into Handle(DataChat)
  • SendTo(...)
    • creates a "server" DataChat to send to specific session (passed through PrepareAndLog)
  • event Action<ChatModule, DataChat>? OnReceive
  • event Action<ChatModule, DataChat>? OnForceSend
  • ForceSend(DataChat)
    • uhh something

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    TODO soon-ish-ish

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions