mirror of
https://github.com/CPunch/gopenfusion.git
synced 2024-12-04 14:36:02 +00:00
Compare commits
2 Commits
3559d9ba9b
...
f27e72d68d
Author | SHA1 | Date | |
---|---|---|---|
f27e72d68d | |||
215e313c43 |
56
shard/chat.go
Normal file
56
shard/chat.go
Normal 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,
|
||||
})
|
||||
}
|
@ -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 {
|
||||
|
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user