mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-15 00:15:08 +01:00
stringstack patches
This commit is contained in:
@@ -2,33 +2,45 @@ package stringstack
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// StringStack is a basic LIFO "stack" for storing strings.
|
// StringStack is a basic LIFO "stack" for storing strings.
|
||||||
type StringStack struct {
|
type StringStack struct {
|
||||||
sync.Mutex
|
Locked bool
|
||||||
stack []string
|
stack []string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new instance of StringStack
|
// New creates a new instance of StringStack
|
||||||
func New() *StringStack {
|
func New() *StringStack {
|
||||||
return &StringStack{}
|
return &StringStack{Locked: false}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set sets up a new StringStack
|
||||||
|
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.
|
// Push pushes a string onto the stack.
|
||||||
func (s *StringStack) Push(v string) {
|
func (s *StringStack) Push(v string) {
|
||||||
s.Lock()
|
|
||||||
defer s.Unlock()
|
|
||||||
|
|
||||||
s.stack = append(s.stack, v)
|
s.stack = append(s.stack, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pop pops a string from the stack.
|
// Pop pops a string from the stack.
|
||||||
func (s *StringStack) Pop() (string, error) {
|
func (s *StringStack) Pop() (string, error) {
|
||||||
s.Lock()
|
|
||||||
defer s.Unlock()
|
|
||||||
|
|
||||||
if len(s.stack) == 0 {
|
if len(s.stack) == 0 {
|
||||||
return "", errors.New("no items on stack")
|
return "", errors.New("no items on stack")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,10 +120,14 @@ func removeSessionFromStage(s *Session) {
|
|||||||
|
|
||||||
func handleMsgSysEnterStage(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgSysEnterStage(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgSysEnterStage)
|
pkt := p.(*mhfpacket.MsgSysEnterStage)
|
||||||
|
|
||||||
// Push our current stage ID to the movement stack before entering another one.
|
// Push our current stage ID to the movement stack before entering another one.
|
||||||
s.Lock()
|
if s.stageID == "" {
|
||||||
s.stageMoveStack.Push(s.stageID)
|
s.stageMoveStack.Set(pkt.StageID)
|
||||||
s.Unlock()
|
} else {
|
||||||
|
s.stageMoveStack.Push(s.stageID)
|
||||||
|
s.stageMoveStack.Lock()
|
||||||
|
}
|
||||||
|
|
||||||
s.QueueSendMHF(&mhfpacket.MsgSysCleanupObject{})
|
s.QueueSendMHF(&mhfpacket.MsgSysCleanupObject{})
|
||||||
if s.reservationStage != nil {
|
if s.reservationStage != nil {
|
||||||
@@ -137,9 +141,8 @@ func handleMsgSysBackStage(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
pkt := p.(*mhfpacket.MsgSysBackStage)
|
pkt := p.(*mhfpacket.MsgSysBackStage)
|
||||||
|
|
||||||
// Transfer back to the saved stage ID before the previous move or enter.
|
// Transfer back to the saved stage ID before the previous move or enter.
|
||||||
s.Lock()
|
s.stageMoveStack.Unlock()
|
||||||
backStage, err := s.stageMoveStack.Pop()
|
backStage, err := s.stageMoveStack.Pop()
|
||||||
s.Unlock()
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -151,10 +154,10 @@ func handleMsgSysBackStage(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
func handleMsgSysMoveStage(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgSysMoveStage(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgSysMoveStage)
|
pkt := p.(*mhfpacket.MsgSysMoveStage)
|
||||||
|
|
||||||
// Push our current stage ID to the movement stack before entering another one.
|
// Set a new move stack from the given stage ID if unlocked
|
||||||
s.Lock()
|
if !s.stageMoveStack.Locked {
|
||||||
s.stageMoveStack.Push(s.stageID)
|
s.stageMoveStack.Set(pkt.StageID)
|
||||||
s.Unlock()
|
}
|
||||||
|
|
||||||
doStageTransfer(s, pkt.AckHandle, pkt.StageID)
|
doStageTransfer(s, pkt.AckHandle, pkt.StageID)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user