-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
99 lines (86 loc) · 3.53 KB
/
Copy pathmain.go
File metadata and controls
99 lines (86 loc) · 3.53 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Package main implements a simple test gamemode to verify the ompgo integration.
package main
import (
"context"
"log"
"github.com/ompgo-dev/ompgo/pkg/omp"
"github.com/ompgo-dev/ompgo/pkg/omp/all"
"github.com/ompgo-dev/ompgo/pkg/omp/class"
"github.com/ompgo-dev/ompgo/pkg/omp/core"
"github.com/ompgo-dev/ompgo/pkg/omp/players"
"github.com/ompgo-dev/ompgo/pkg/runtime"
)
// TestGamemode is a minimal gamemode for testing
type TestGamemode struct {
omp.BaseEventHandler
}
func (g *TestGamemode) OnLoad(ctx context.Context) error {
log.Println("[TestGamemode] OnLoad called")
_ = core.GameModeSetText("ompgo Test Mode")
classID1 := int32(-1)
classID2 := int32(-1)
_ = class.Add(0, 0, 1958.3783, 1343.1572, 15.3746, 270.1425, 0, 0, 0, 0, 0, 0, &classID1)
_ = class.Add(1, 0, 1958.3783, 1343.1572, 15.3746, 270.1425, 0, 0, 0, 0, 0, 0, &classID2)
log.Println("[TestGamemode] Initialization complete")
log.Println("[TestGamemode] Gamemode: ompgo Test Mode")
log.Println("[TestGamemode] Version: 0.1.0")
log.Println("[TestGamemode] Ready to accept players!")
return nil
}
// OnPlayerConnect is called when a player connects
func (g *TestGamemode) OnPlayerConnect(ctx context.Context, event *omp.PlayerConnectEvent) error {
log.Printf("[TestGamemode] Player connected")
if event.Player == nil || !event.Player.Valid() {
return nil
}
name, _ := players.GetName(event.Player)
log.Printf("[TestGamemode] Player name: %s", name)
msg := "Welcome to ompgo Test Server, " + name + "!"
_ = players.SendClientMessage(event.Player, uint32(omp.ColorGreen), msg)
_ = players.SendClientMessage(event.Player, uint32(omp.ColorYellow), "This server is running Go!")
_ = all.SendClientMessage(uint32(omp.ColorGrey), name+" has joined the server.")
return nil
}
// OnPlayerDisconnect is called when a player disconnects
func (g *TestGamemode) OnPlayerDisconnect(ctx context.Context, event *omp.PlayerDisconnectEvent) error {
if event.Player == nil || !event.Player.Valid() {
return nil
}
name, _ := players.GetName(event.Player)
log.Printf("[TestGamemode] Player (%s) disconnected", name)
_ = all.SendClientMessage(uint32(omp.ColorGrey), name+" has left the server.")
return nil
}
// OnPlayerSpawn is called when a player spawns
func (g *TestGamemode) OnPlayerSpawn(ctx context.Context, event *omp.PlayerSpawnEvent) error {
if event.Player == nil || !event.Player.Valid() {
return nil
}
name, _ := players.GetName(event.Player)
log.Printf("[TestGamemode] Player (%s) spawned", name)
_ = players.SendClientMessage(event.Player, uint32(omp.ColorGreen), "You have spawned! Type /help for commands.")
return nil
}
// OnPlayerText is called when a player sends a chat message
func (g *TestGamemode) OnPlayerText(ctx context.Context, event *omp.PlayerTextEvent) (bool, error) {
if event.Player == nil || !event.Player.Valid() {
return false, nil
}
name, _ := players.GetName(event.Player)
log.Printf("[TestGamemode] %s: %s", name, event.Text.Clone())
return false, nil
}
// OnPlayerCommandText is called when a player types a command
func (g *TestGamemode) OnPlayerCommandText(ctx context.Context, event *omp.PlayerCommandTextEvent) (bool, error) {
if event.Player == nil || !event.Player.Valid() {
return false, nil
}
name, _ := players.GetName(event.Player)
log.Printf("[TestGamemode] %s typed: %s", name, event.Command.Clone())
_ = players.SendClientMessage(event.Player, uint32(omp.ColorGreen), "Commands are logged to console")
return true, nil
}
// NewGamemode returns the test gamemode instance
func NewGamemode() runtime.Gamemode {
return &TestGamemode{}
}