gopenfusion/shard/chat.go
CPunch f4b17906ce more protocol/service refactor
- removed protocol.Event: CNPeers now send protocol.PacketEvents
- peer uData is held in CNPeer, use SetUserData() and UserData() to
set/read it
- Service.PacketHandler calback has changed, removed uData:
switched calls to peer.SetUserData() and peer.UserData() where appropriate
- service.Service lots of tidying up, removed dependence on old
protocol.Event.
- service.Service && protocol.CNPeer now accept a cancelable context.
hooray graceful shutdowns and unit tests!
- general cleanup
2023-12-01 00:56:34 -06:00

59 lines
1.7 KiB
Go

package shard
import (
"fmt"
"github.com/CPunch/gopenfusion/internal/entity"
"github.com/CPunch/gopenfusion/internal/protocol"
)
func (server *ShardServer) freeChat(peer *protocol.CNPeer, pkt protocol.Packet) error {
var chat protocol.SP_CL2FE_REQ_SEND_FREECHAT_MESSAGE
pkt.Decode(&chat)
plr, ok := peer.UserData().(*entity.Player)
if !ok || plr == nil {
return fmt.Errorf("freeChat: plr is nil")
}
// 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)
plr, ok := peer.UserData().(*entity.Player)
if !ok || plr == nil {
return fmt.Errorf("menuChat: plr is nil")
}
// 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)
plr, ok := peer.UserData().(*entity.Player)
if !ok || plr == nil {
return fmt.Errorf("emoteChat: plr is nil")
}
// 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,
})
}