From 8cea6235c85304d94a208547cccdf9d8ef086263 Mon Sep 17 00:00:00 2001 From: Andrew Gutekanst Date: Wed, 19 Feb 2020 08:13:41 -0500 Subject: [PATCH] Implement stage object deletion --- network/mhfpacket/msg_sys_delete_object.go | 12 ++++++++---- server/channelserver/handlers.go | 20 ++++++++++++++++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/network/mhfpacket/msg_sys_delete_object.go b/network/mhfpacket/msg_sys_delete_object.go index 817060e03..13d951103 100644 --- a/network/mhfpacket/msg_sys_delete_object.go +++ b/network/mhfpacket/msg_sys_delete_object.go @@ -6,7 +6,9 @@ import ( ) // MsgSysDeleteObject represents the MSG_SYS_DELETE_OBJECT -type MsgSysDeleteObject struct{} +type MsgSysDeleteObject struct { + ObjID uint32 +} // Opcode returns the ID associated with this packet type. func (m *MsgSysDeleteObject) Opcode() network.PacketID { @@ -15,10 +17,12 @@ func (m *MsgSysDeleteObject) Opcode() network.PacketID { // Parse parses the packet from binary func (m *MsgSysDeleteObject) Parse(bf *byteframe.ByteFrame) error { - panic("Not implemented") + m.ObjID = bf.ReadUint32() + return nil } // Build builds a binary packet from the current data. func (m *MsgSysDeleteObject) Build(bf *byteframe.ByteFrame) error { - panic("Not implemented") -} \ No newline at end of file + bf.WriteUint32(m.ObjID) + return nil +} diff --git a/server/channelserver/handlers.go b/server/channelserver/handlers.go index 5bfd965ca..d75fbfc02 100644 --- a/server/channelserver/handlers.go +++ b/server/channelserver/handlers.go @@ -304,16 +304,32 @@ func handleMsgSysCreateStage(s *Session, p mhfpacket.MHFPacket) { func handleMsgSysStageDestruct(s *Session, p mhfpacket.MHFPacket) {} func doStageTransfer(s *Session, ackHandle uint32, stageID string) { - // Remove this session from old stage clients list and put myself in the new one. s.server.stagesLock.Lock() newStage, gotNewStage := s.server.stages[stripNullTerminator(stageID)] s.server.stagesLock.Unlock() - // Remove from old stage. if s.stage != nil { s.stage.Lock() + + // Remove client from old stage. delete(s.stage.clients, s) + + // Delete old stage objects owned by the client. + s.logger.Info("Sending MsgSysDeleteObject to old stage clients") + for objID, stageObject := range s.stage.objects { + if stageObject.ownerCharID == s.charID { + // Broadcast the deletion to clients in the stage. + s.stage.BroadcastMHF(&mhfpacket.MsgSysDeleteObject{ + ObjID: stageObject.id, + }, s) + // TODO(Andoryuuta): Should this be sent to the owner's client as well? it currently isn't. + + // Actually delete it form the objects map. + delete(s.stage.objects, objID) + } + } + s.stage.Unlock() }