Compare commits

...

2 Commits

Author SHA1 Message Date
f27e72d68d send chat packets to *all* players 2023-06-27 22:05:08 -05:00
215e313c43 added chat :D 2023-06-27 21:49:11 -05:00
3 changed files with 75 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.sendAllPacket(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.sendAllPacket(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.sendAllPacket(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) {
// TODO: chunk cleanup
pos := e.GetChunk()
server.removeEntityFromChunks(server.getViewableChunks(pos), e)
server.getChunk(pos).RemoveEntity(e)
@ -45,6 +46,16 @@ func (server *ShardServer) sendOthersPacket(plr *entity.Player, typeID uint32, p
return nil
}
// sends a packet to all peers in the given chunks
func (server *ShardServer) sendAllPacket(plr *entity.Player, typeID uint32, pkt ...interface{}) error {
chunks := server.getViewableChunks(plr.Chunk)
for _, chunk := range chunks {
chunk.SendPacket(typeID, pkt...)
}
return nil
}
func (server *ShardServer) removeEntityFromChunks(chunks []*entity.Chunk, this entity.Entity) {
for _, chunk := range chunks {
for e := range chunk.Entities {

View File

@ -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{