mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-13 07:25:03 +01:00
rewrite stringstack.go
This commit is contained in:
@@ -6,13 +6,12 @@ import (
|
||||
|
||||
// StringStack is a basic LIFO "stack" for storing strings.
|
||||
type StringStack struct {
|
||||
Locked bool
|
||||
stack []string
|
||||
}
|
||||
|
||||
// New creates a new instance of StringStack
|
||||
func New() *StringStack {
|
||||
return &StringStack{Locked: false}
|
||||
return &StringStack{}
|
||||
}
|
||||
|
||||
// Set sets up a new StringStack
|
||||
@@ -20,20 +19,6 @@ func (s *StringStack) Set(v string) {
|
||||
s.stack = []string{v}
|
||||
}
|
||||
|
||||
// Lock freezes the StringStack
|
||||
func (s *StringStack) Lock() {
|
||||
if !s.Locked {
|
||||
s.Locked = true
|
||||
}
|
||||
}
|
||||
|
||||
// Unlock unfreezes the StringStack
|
||||
func (s *StringStack) Unlock() {
|
||||
if s.Locked {
|
||||
s.Locked = false
|
||||
}
|
||||
}
|
||||
|
||||
// Push pushes a string onto the stack.
|
||||
func (s *StringStack) Push(v string) {
|
||||
s.stack = append(s.stack, v)
|
||||
|
||||
@@ -152,14 +152,11 @@ func handleMsgSysEnterStage(s *Session, p mhfpacket.MHFPacket) {
|
||||
pkt := p.(*mhfpacket.MsgSysEnterStage)
|
||||
|
||||
// Push our current stage ID to the movement stack before entering another one.
|
||||
if s.stage.id == "" {
|
||||
s.stageMoveStack.Set(pkt.StageID)
|
||||
} else {
|
||||
if s.stage != nil {
|
||||
s.stage.Lock()
|
||||
s.stage.reservedClientSlots[s.charID] = false
|
||||
s.stage.Unlock()
|
||||
s.stageMoveStack.Push(s.stage.id)
|
||||
s.stageMoveStack.Lock()
|
||||
}
|
||||
|
||||
if s.reservationStage != nil {
|
||||
@@ -173,7 +170,6 @@ func handleMsgSysBackStage(s *Session, p mhfpacket.MHFPacket) {
|
||||
pkt := p.(*mhfpacket.MsgSysBackStage)
|
||||
|
||||
// Transfer back to the saved stage ID before the previous move or enter.
|
||||
s.stageMoveStack.Unlock()
|
||||
backStage, err := s.stageMoveStack.Pop()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -193,10 +189,8 @@ func handleMsgSysBackStage(s *Session, p mhfpacket.MHFPacket) {
|
||||
func handleMsgSysMoveStage(s *Session, p mhfpacket.MHFPacket) {
|
||||
pkt := p.(*mhfpacket.MsgSysMoveStage)
|
||||
|
||||
// Set a new move stack from the given stage ID if unlocked
|
||||
if !s.stageMoveStack.Locked {
|
||||
// Set a new move stack from the given stage ID
|
||||
s.stageMoveStack.Set(pkt.StageID)
|
||||
}
|
||||
|
||||
doStageTransfer(s, pkt.AckHandle, pkt.StageID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user