Execute on join commands
(e events.Event)
| 16 | // |
| 17 | |
| 18 | func HandleJoin(e events.Event) events.ListenerReturn { |
| 19 | |
| 20 | evt, typeOk := e.(events.PlayerSpawn) |
| 21 | if !typeOk { |
| 22 | mudlog.Error("Event", "Expected Type", "PlayerSpawn", "Actual Type", e.Type()) |
| 23 | return events.Cancel |
| 24 | } |
| 25 | |
| 26 | user := users.GetByUserId(evt.UserId) |
| 27 | if user == nil { |
| 28 | mudlog.Error("HandleJoin", "error", fmt.Sprintf(`user %d not found`, evt.UserId)) |
| 29 | return events.Cancel |
| 30 | } |
| 31 | |
| 32 | user.EventLog.Add(`conn`, fmt.Sprintf(`<ansi fg="username">%s</ansi> entered the world`, user.Character.Name)) |
| 33 | |
| 34 | users.RemoveLinkDeadUser(evt.UserId) |
| 35 | |
| 36 | room := rooms.LoadRoom(user.Character.RoomId) |
| 37 | sendResetMessage := false |
| 38 | |
| 39 | // If an onreset room is set, send to it, then clear it. |
| 40 | // This way, if they were in an ephemeral chunk and it has been cleared, we |
| 41 | // handle sending them to whatever "reset" room was defined (if any) |
| 42 | if room == nil && user.Character.RoomIdOnReset != 0 { |
| 43 | mudlog.Warn("HandleJoin", "msg", fmt.Sprintf("room %d not found, trying RoomIdOnReset %d", user.Character.RoomId, user.Character.RoomIdOnReset)) |
| 44 | room = rooms.LoadRoom(user.Character.RoomIdOnReset) |
| 45 | |
| 46 | if room != nil { |
| 47 | sendResetMessage = true |
| 48 | user.Character.RoomId = user.Character.RoomIdOnReset |
| 49 | } |
| 50 | |
| 51 | user.Character.RoomIdOnReset = 0 |
| 52 | } |
| 53 | |
| 54 | // If still no room was found, send to the zero room (default world start room) |
| 55 | if room == nil { |
| 56 | mudlog.Error("EnterWorld", "error", fmt.Sprintf(`room %d not found`, user.Character.RoomId)) |
| 57 | |
| 58 | if err := rooms.MoveToRoom(user.UserId, 0); err != nil { |
| 59 | mudlog.Error("EnterWorld", "msg", "could not move to room 0", "error", err) |
| 60 | } |
| 61 | |
| 62 | // Load whatever default room they have been assigned |
| 63 | room = rooms.LoadRoom(user.Character.RoomId) |
| 64 | sendResetMessage = true |
| 65 | } |
| 66 | |
| 67 | // TODO HERE |
| 68 | if user.HasPlaintextPassword() { |
| 69 | user.SendText(`<ansi fg="alert-5">You must change your password before doing anything else.</ansi>`) |
| 70 | user.SendText(`<ansi fg="yellow">Type <ansi fg="yellow-bold">password</ansi> to set a new password.</ansi>`) |
| 71 | } else { |
| 72 | loginCmds := configs.GetConfig().Server.OnLoginCommands |
| 73 | if len(loginCmds) > 0 { |
| 74 | |
| 75 | for _, cmd := range loginCmds { |
nothing calls this directly
no test coverage detected