-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathworld.roundtick.go
61 lines (41 loc) · 1.36 KB
/
world.roundtick.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"github.com/volte6/gomud/internal/connections"
"github.com/volte6/gomud/internal/events"
"github.com/volte6/gomud/internal/mudlog"
"github.com/volte6/gomud/internal/rooms"
"github.com/volte6/gomud/internal/templates"
"github.com/volte6/gomud/internal/users"
)
func (w *World) logOff(userId int) {
if user := users.GetByUserId(userId); user != nil {
user.EventLog.Add(`conn`, `Logged off`)
users.SaveUser(*user)
events.AddToQueue(events.PlayerDespawn{UserId: userId})
connId := user.ConnectionId()
tplTxt, _ := templates.Process("goodbye", nil, templates.AnsiTagsPreParse)
connections.SendTo([]byte(tplTxt), connId)
if err := users.LogOutUserByConnectionId(connId); err != nil {
mudlog.Error("Log Out Error", "connectionId", connId, "error", err)
}
connections.Remove(connId)
}
}
// Handle dropped players
func (w *World) HandleDroppedPlayers(droppedPlayers []int) {
if len(droppedPlayers) == 0 {
return
}
for _, userId := range droppedPlayers {
if user := users.GetByUserId(userId); user != nil {
user.SendText(`<ansi fg="red">you drop to the ground!</ansi>`)
if room := rooms.LoadRoom(user.Character.RoomId); room != nil {
room.SendText(
fmt.Sprintf(`<ansi fg="username">%s</ansi> <ansi fg="red">drops to the ground!</ansi>`, user.Character.Name),
user.UserId)
}
}
}
return
}