Fix chat messages not arriving at the MT server

master
HimbeerserverDE 2021-04-18 16:21:00 +02:00
parent 5a4e6fb740
commit 2b8d7ed330
No known key found for this signature in database
GPG Key ID: 1A651504791E6A8B
3 changed files with 8 additions and 6 deletions

10
chat.go
View File

@ -56,11 +56,11 @@ func RegisterOnServerChatMessage(function func(*Conn, string) bool) {
onServerChatMsg = append(onServerChatMsg, function)
}
func processChatMessage(c *Conn, pkt rudp.Pkt) bool {
r := ByteReader(pkt)
func processChatMessage(c *Conn, r *bytes.Reader) bool {
r.Seek(2, io.SeekCurrent)
wstr := make([]byte, r.Len()-4)
r.ReadAt(wstr, 4)
wstr := make([]byte, r.Len())
r.Read(wstr)
s := string(narrow(wstr))
if strings.HasPrefix(s, ChatCommandPrefix) {
@ -68,6 +68,8 @@ func processChatMessage(c *Conn, pkt rudp.Pkt) bool {
s = strings.Replace(s, ChatCommandPrefix, "", 1)
params := strings.Split(s, " ")
log.Print(c.Username(), " issued command: ", s)
// Priv check
allow, err := c.CheckPrivs(chatCommands[params[0]].privs)
if err != nil {

View File

@ -317,7 +317,7 @@ func processPktCommand(src, dst *Conn, pkt *rudp.Pkt) bool {
} else {
switch cmd := binary.BigEndian.Uint16(cmdBytes); cmd {
case ToServerChatMessage:
return processChatMessage(src, *pkt)
return processChatMessage(src, r)
case ToServerFirstSRP:
if src.sudoMode {
src.sudoMode = false

View File

@ -128,7 +128,7 @@ func initCurses(l *Logger) {
consoleInput = []rune{}
if chatCommands[params[0]].function == nil {
log.Print("Unknown command " + params[0] + ".")
log.Print("Unknown command ", params[0])
continue
}