if err != nil {
return res, err
}
- if err := os.WriteFile(cc.Server.ConfigDir+"Users/"+login+".yaml", out, 0666); err != nil {
+ if err := os.WriteFile(filepath.Join(cc.Server.ConfigDir, "Users", login+".yaml"), out, 0666); err != nil {
return res, err
}
var userFields []Field
for _, acc := range cc.Server.Accounts {
- userField := acc.MarshalBinary()
- userFields = append(userFields, NewField(fieldData, userField))
+ b := make([]byte, 0, 100)
+ n, err := acc.Read(b)
+ if err != nil {
+ return res, err
+ }
+
+ userFields = append(userFields, NewField(fieldData, b[:n]))
}
res = append(res, cc.NewReply(t, userFields...))
*cc.Icon = t.GetField(fieldUserIconID).Data
cc.logger = cc.logger.With("name", string(cc.UserName))
+ cc.logger.Infow("Login successful", "clientVersion", fmt.Sprintf("%x", *cc.Version))
options := t.GetField(fieldOptions).Data
optBitmap := big.NewInt(int64(binary.BigEndian.Uint16(options)))
return res, err
}
- if err := clientConn.Connection.Close(); err != nil {
- return res, err
+ // If fieldOptions is set, then the client IP is banned in addition to disconnected.
+ // 00 01 = temporary ban
+ // 00 02 = permanent ban
+ if t.GetField(fieldOptions).Data != nil {
+ switch t.GetField(fieldOptions).Data[1] {
+ case 1:
+ // send message: "You are temporarily banned on this server"
+ cc.logger.Infow("Disconnect & temporarily ban " + string(clientConn.UserName))
+
+ res = append(res, *NewTransaction(
+ tranServerMsg,
+ clientConn.ID,
+ NewField(fieldData, []byte("You are temporarily banned on this server")),
+ NewField(fieldChatOptions, []byte{0, 0}),
+ ))
+
+ banUntil := time.Now().Add(tempBanDuration)
+ cc.Server.banList[strings.Split(clientConn.RemoteAddr, ":")[0]] = &banUntil
+ cc.Server.writeBanList()
+ case 2:
+ // send message: "You are permanently banned on this server"
+ cc.logger.Infow("Disconnect & ban " + string(clientConn.UserName))
+
+ res = append(res, *NewTransaction(
+ tranServerMsg,
+ clientConn.ID,
+ NewField(fieldData, []byte("You are permanently banned on this server")),
+ NewField(fieldChatOptions, []byte{0, 0}),
+ ))
+
+ cc.Server.banList[strings.Split(clientConn.RemoteAddr, ":")[0]] = nil
+ cc.Server.writeBanList()
+ }
}
- res = append(res, cc.NewReply(t))
- return res, err
+ // TODO: remove this awful hack
+ go func() {
+ time.Sleep(1 * time.Second)
+ clientConn.Disconnect()
+ }()
+
+ return append(res, cc.NewReply(t)), err
}
// HandleGetNewsCatNameList returns a list of news categories for a path
chatID := t.GetField(fieldChatID).Data
chatInt := binary.BigEndian.Uint32(chatID)
- privChat := cc.Server.PrivateChats[chatInt]
+ privChat, ok := cc.Server.PrivateChats[chatInt]
+ if !ok {
+ return res, nil
+ }
delete(privChat.ClientConn, cc.uint16ID())