aboutsummaryrefslogtreecommitdiff
path: root/internal/net/server.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-09 17:15:13 -0400
committerhistoria <[not public]>2026-06-09 17:15:13 -0400
commit9edc568e16741d443b67fbd23b0d91790085ced9 (patch)
treed54be40531ba124dcf8299f9e94bfba4ece273ae /internal/net/server.go
parent56be6a3f45830594225a765b406816e6179ccde1 (diff)
downloadthehouseoficarus-9edc568e16741d443b67fbd23b0d91790085ced9.tar.gz
combat, mobs, parsing, toggles, hard disconnect handling
Diffstat (limited to 'internal/net/server.go')
-rw-r--r--internal/net/server.go37
1 files changed, 32 insertions, 5 deletions
diff --git a/internal/net/server.go b/internal/net/server.go
index 2a10a9a..fa0b509 100644
--- a/internal/net/server.go
+++ b/internal/net/server.go
@@ -24,6 +24,7 @@ const (
StateDeleteChar
StatePurgeAccount
StateGame
+ StateChangeDescription
)
type Session struct {
@@ -32,8 +33,10 @@ type Session struct {
State SessionState
Account *AccountEntry
Player interface{} // *player.Player once character is selected
- PendingChar string // char being renamed/deleted
- PendingPass string // first password during signup
+ PendingChar string // char being renamed/deleted
+ PendingPass string // first password during signup
+ Disconnecting bool
+ DisconnectTicks int
}
type AccountEntry struct {
@@ -48,9 +51,9 @@ type Server struct {
}
type Hub struct {
- sessions map[*Session]bool
- // roomID -> sessions
- rooms map[int]map[*Session]bool
+ sessions map[*Session]bool
+ rooms map[int]map[*Session]bool
+ onRemove func(*Session)
}
func NewHub() *Hub {
@@ -60,15 +63,31 @@ func NewHub() *Hub {
}
}
+func (h *Hub) OnRemove(cb func(*Session)) {
+ h.onRemove = cb
+}
+
func (h *Hub) Add(s *Session) {
h.sessions[s] = true
}
func (h *Hub) Remove(s *Session) {
+ if s.Player != nil && s.State == StateGame && !s.Disconnecting {
+ s.Disconnecting = true
+ s.DisconnectTicks = 10
+ return
+ }
+ h.HardRemove(s)
+}
+
+func (h *Hub) HardRemove(s *Session) {
delete(h.sessions, s)
for _, room := range h.rooms {
delete(room, s)
}
+ if h.onRemove != nil {
+ h.onRemove(s)
+ }
}
func (h *Hub) EnterRoom(s *Session, roomID int) {
@@ -85,6 +104,14 @@ func (h *Hub) LeaveRoom(s *Session) {
}
}
+func (h *Hub) AllSessions() []*Session {
+ var out []*Session
+ for s := range h.sessions {
+ out = append(out, s)
+ }
+ return out
+}
+
func (h *Hub) PlayersInRoom(roomID int) []*Session {
var out []*Session
if room, ok := h.rooms[roomID]; ok {