mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-15 00:15:08 +01:00
Implement stage object deletion
This commit is contained in:
@@ -6,7 +6,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// MsgSysDeleteObject represents the MSG_SYS_DELETE_OBJECT
|
// MsgSysDeleteObject represents the MSG_SYS_DELETE_OBJECT
|
||||||
type MsgSysDeleteObject struct{}
|
type MsgSysDeleteObject struct {
|
||||||
|
ObjID uint32
|
||||||
|
}
|
||||||
|
|
||||||
// Opcode returns the ID associated with this packet type.
|
// Opcode returns the ID associated with this packet type.
|
||||||
func (m *MsgSysDeleteObject) Opcode() network.PacketID {
|
func (m *MsgSysDeleteObject) Opcode() network.PacketID {
|
||||||
@@ -15,10 +17,12 @@ func (m *MsgSysDeleteObject) Opcode() network.PacketID {
|
|||||||
|
|
||||||
// Parse parses the packet from binary
|
// Parse parses the packet from binary
|
||||||
func (m *MsgSysDeleteObject) Parse(bf *byteframe.ByteFrame) error {
|
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.
|
// Build builds a binary packet from the current data.
|
||||||
func (m *MsgSysDeleteObject) Build(bf *byteframe.ByteFrame) error {
|
func (m *MsgSysDeleteObject) Build(bf *byteframe.ByteFrame) error {
|
||||||
panic("Not implemented")
|
bf.WriteUint32(m.ObjID)
|
||||||
}
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -304,16 +304,32 @@ func handleMsgSysCreateStage(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
func handleMsgSysStageDestruct(s *Session, p mhfpacket.MHFPacket) {}
|
func handleMsgSysStageDestruct(s *Session, p mhfpacket.MHFPacket) {}
|
||||||
|
|
||||||
func doStageTransfer(s *Session, ackHandle uint32, stageID string) {
|
func doStageTransfer(s *Session, ackHandle uint32, stageID string) {
|
||||||
|
|
||||||
// Remove this session from old stage clients list and put myself in the new one.
|
// Remove this session from old stage clients list and put myself in the new one.
|
||||||
s.server.stagesLock.Lock()
|
s.server.stagesLock.Lock()
|
||||||
newStage, gotNewStage := s.server.stages[stripNullTerminator(stageID)]
|
newStage, gotNewStage := s.server.stages[stripNullTerminator(stageID)]
|
||||||
s.server.stagesLock.Unlock()
|
s.server.stagesLock.Unlock()
|
||||||
|
|
||||||
// Remove from old stage.
|
|
||||||
if s.stage != nil {
|
if s.stage != nil {
|
||||||
s.stage.Lock()
|
s.stage.Lock()
|
||||||
|
|
||||||
|
// Remove client from old stage.
|
||||||
delete(s.stage.clients, s)
|
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()
|
s.stage.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user