Implement stage object deletion

This commit is contained in:
Andrew Gutekanst
2020-02-19 08:13:41 -05:00
parent e5f2650871
commit 8cea6235c8
2 changed files with 26 additions and 6 deletions

View File

@@ -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")
}
bf.WriteUint32(m.ObjID)
return nil
}

View File

@@ -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()
}