From 215e313c43163f78157d88184e2abfe6106f93a5 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 27 Jun 2023 21:49:11 -0500 Subject: [PATCH] added chat :D --- shard/chat.go | 56 ++++++++++++++++++++++++++++++++++++++++++ shard/entitymanager.go | 1 + shard/shardserver.go | 13 ++++++---- 3 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 shard/chat.go diff --git a/shard/chat.go b/shard/chat.go new file mode 100644 index 0000000..4ada26a --- /dev/null +++ b/shard/chat.go @@ -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, + }) +} diff --git a/shard/entitymanager.go b/shard/entitymanager.go index 3d7cb83..1d98005 100644 --- a/shard/entitymanager.go +++ b/shard/entitymanager.go @@ -11,6 +11,7 @@ func (server *ShardServer) addEntity(e entity.Entity) { } func (server *ShardServer) removeEntity(e entity.Entity) { + // TODO: chunk cleanup pos := e.GetChunk() server.removeEntityFromChunks(server.getViewableChunks(pos), e) server.getChunk(pos).RemoveEntity(e) diff --git a/shard/shardserver.go b/shard/shardserver.go index 0d2b5fd..019b8b1 100644 --- a/shard/shardserver.go +++ b/shard/shardserver.go @@ -48,11 +48,14 @@ func NewShardServer(dbHndlr *db.DBHandler, redisHndlr *redis.RedisHandler, port } server.packetHandlers = map[uint32]PacketHandler{ - protocol.P_CL2FE_REQ_PC_ENTER: server.RequestEnter, - protocol.P_CL2FE_REQ_PC_LOADING_COMPLETE: server.LoadingComplete, - protocol.P_CL2FE_REQ_PC_MOVE: server.playerMove, - protocol.P_CL2FE_REQ_PC_STOP: server.playerStop, - protocol.P_CL2FE_REQ_PC_JUMP: server.playerJump, + protocol.P_CL2FE_REQ_PC_ENTER: server.RequestEnter, + protocol.P_CL2FE_REQ_PC_LOADING_COMPLETE: server.LoadingComplete, + protocol.P_CL2FE_REQ_PC_MOVE: server.playerMove, + protocol.P_CL2FE_REQ_PC_STOP: server.playerStop, + 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{