added chat :D

This commit is contained in:
unknown 2023-06-27 21:49:11 -05:00
parent 3559d9ba9b
commit 215e313c43
3 changed files with 65 additions and 5 deletions

56
shard/chat.go Normal file
View File

@ -0,0 +1,56 @@
package shard
import "github.com/CPunch/gopenfusion/core/protocol"
func (server *ShardServer) freeChat(peer *protocol.CNPeer, pkt protocol.Packet) error {
var chat protocol.SP_CL2FE_REQ_SEND_FREECHAT_MESSAGE
pkt.Decode(&chat)
// sanity check
plr, err := server.getPlayer(peer)
if err != nil {
return err
}
// spread message
return server.sendOthersPacket(plr, protocol.P_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC, protocol.SP_FE2CL_REP_SEND_FREECHAT_MESSAGE_SUCC{
IPC_ID: int32(plr.PlayerID),
SzFreeChat: chat.SzFreeChat,
IEmoteCode: chat.IEmoteCode,
})
}
func (server *ShardServer) menuChat(peer *protocol.CNPeer, pkt protocol.Packet) error {
var chat protocol.SP_CL2FE_REQ_SEND_MENUCHAT_MESSAGE
pkt.Decode(&chat)
// sanity check
plr, err := server.getPlayer(peer)
if err != nil {
return err
}
// spread message
return server.sendOthersPacket(plr, protocol.P_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC, protocol.SP_FE2CL_REP_SEND_MENUCHAT_MESSAGE_SUCC{
IPC_ID: int32(plr.PlayerID),
SzFreeChat: chat.SzFreeChat,
IEmoteCode: chat.IEmoteCode,
})
}
func (server *ShardServer) emoteChat(peer *protocol.CNPeer, pkt protocol.Packet) error {
var chat protocol.SP_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT
pkt.Decode(&chat)
// sanity check
plr, err := server.getPlayer(peer)
if err != nil {
return err
}
// spread message
return server.sendOthersPacket(plr, protocol.P_FE2CL_REP_PC_AVATAR_EMOTES_CHAT, protocol.SP_FE2CL_REP_PC_AVATAR_EMOTES_CHAT{
IID_From: int32(plr.PlayerID),
IEmoteCode: chat.IEmoteCode,
})
}

View File

@ -11,6 +11,7 @@ func (server *ShardServer) addEntity(e entity.Entity) {
} }
func (server *ShardServer) removeEntity(e entity.Entity) { func (server *ShardServer) removeEntity(e entity.Entity) {
// TODO: chunk cleanup
pos := e.GetChunk() pos := e.GetChunk()
server.removeEntityFromChunks(server.getViewableChunks(pos), e) server.removeEntityFromChunks(server.getViewableChunks(pos), e)
server.getChunk(pos).RemoveEntity(e) server.getChunk(pos).RemoveEntity(e)

View File

@ -53,6 +53,9 @@ func NewShardServer(dbHndlr *db.DBHandler, redisHndlr *redis.RedisHandler, port
protocol.P_CL2FE_REQ_PC_MOVE: server.playerMove, protocol.P_CL2FE_REQ_PC_MOVE: server.playerMove,
protocol.P_CL2FE_REQ_PC_STOP: server.playerStop, protocol.P_CL2FE_REQ_PC_STOP: server.playerStop,
protocol.P_CL2FE_REQ_PC_JUMP: server.playerJump, protocol.P_CL2FE_REQ_PC_JUMP: server.playerJump,
protocol.P_CL2FE_REQ_SEND_FREECHAT_MESSAGE: server.freeChat,
protocol.P_CL2FE_REQ_SEND_MENUCHAT_MESSAGE: server.menuChat,
protocol.P_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT: server.emoteChat,
} }
redisHndlr.RegisterShard(redis.ShardMetadata{ redisHndlr.RegisterShard(redis.ShardMetadata{