Skip to content

Commit

Permalink
Merge pull request #8 from uiosun/hotfix-deadlock
Browse files Browse the repository at this point in the history
Fix deadlock when clear client
  • Loading branch information
gabereiser authored Mar 5, 2024
2 parents cea8c3f + 6536261 commit 098961f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 11 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ Growing up I used to play muds. I loved them. There was a mud called SWR based o
that recreated the Star Wars universe in text based form. It was pretty good and other muds formed by forking the source and adding
their contributions.

SWR is a reimagining of that codebase without the merc/diku/smaug legacy. Instead it's a pure go mud with some javascript for scripting
SWR is a reimagining of that codebase without the merc/diku/smaug legacy. Instead, it's a pure go mud with some javascript for scripting
that is more flexible and robust than the C mud engines of old.


## Features
- TELNET echo/no-echo
- ANSI Colors
Expand Down
2 changes: 1 addition & 1 deletion swr/act_wiz.go
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ func do_mob_remove(entity Entity, args ...string) {
return
}
tch := target.GetCharData()
DB().RemoveEntity(target)
DB().RemoveEntity(target, false)
delete(DB().mobs, tch.OId)
err := os.Remove(tch.Filename)
ErrorCheck(err)
Expand Down
10 changes: 6 additions & 4 deletions swr/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (d *GameDatabase) RemoveClient(client Client) {
p := e.(*PlayerProfile)
if p.Client != nil {
if p.Client == client {
d.RemoveEntity(e)
d.RemoveEntity(e, true)
}
}
}
Expand All @@ -134,9 +134,11 @@ func (d *GameDatabase) RemoveClient(client Client) {
}
}

func (d *GameDatabase) RemoveEntity(entity Entity) {
d.Lock()
defer d.Unlock()
func (d *GameDatabase) RemoveEntity(entity Entity, isLocked bool) {
if !isLocked {
d.Lock()
defer d.Unlock()
}
if entity == nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion swr/fight.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func make_corpse(entity Entity) {
DB().SavePlayerData(entity.(*PlayerProfile))
return
} else {
DB().RemoveEntity(entity)
DB().RemoveEntity(entity, false)
}
}
}
2 changes: 1 addition & 1 deletion swr/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type ItemData struct {
Type string `yaml:"type"` // item type, a value of ITEM_TYPE_* const.
Value int `yaml:"value"` // how much is this item generally worth?
Weight int `yaml:"weight"` // how much does this item weigh?
AC int `yaml:"ac,omitempty"` // If armor, what's the AC (common AC values are 1-8 for torso, 2-3 for hands/head/feet, 0-1 for waist)
AC int `yaml:"ac,omitempty"` // If armored, what's the AC (common AC values are 1-8 for torso, 2-3 for hands/head/feet, 0-1 for waist)
WearLoc *string `yaml:"wearLoc,omitempty"` // where is this item worn? nil means it's not wearable.
WeaponType *string `yaml:"weaponType,omitempty"` // weapon type from ITEM_WEAPON_TYPE_* const, nil means it's not a weapon.
Dmg *string `yaml:"dmgRoll,omitempty"` // Damage roll represented by a D20 compatible string. Weapons do damage.
Expand Down
2 changes: 0 additions & 2 deletions swr/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func (c *TCPClient) Read() string {
i, err := c.Con.Read(b)
if err != nil {
c.Close()
c.Con.Close()
return buf
}
if i > 0 {
Expand Down Expand Up @@ -205,7 +204,6 @@ func ServerStart(addr string) {
go acceptClient(c)
log.Printf("Accepted client connection from %s", c.RemoteAddr())
}

}
ServerRunning = false
}
Expand Down

0 comments on commit 098961f

Please sign in to comment.