Compare commits
3 Commits
feature/ch
...
a48fef0186
Author | SHA1 | Date | |
---|---|---|---|
a48fef0186 | |||
67e08c5d1e | |||
49e2311497 |
75
README.md
Normal file
75
README.md
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
# GoonServer
|
||||||
|
|
||||||
|
The server component for GoonScape, handling multiplayer synchronization and chat.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Tick-based game state synchronization
|
||||||
|
- Player movement validation
|
||||||
|
- Global chat system
|
||||||
|
- Client connection management
|
||||||
|
- Protobuf-based network protocol
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
- Go 1.23 or higher
|
||||||
|
- Protocol Buffers compiler (protoc)
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
1. Clone the repository:
|
||||||
|
```bash
|
||||||
|
git clone https://gitea.boner.be/bdnugget/goonserver.git
|
||||||
|
cd goonserver
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Install dependencies:
|
||||||
|
```bash
|
||||||
|
go mod tidy
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Build and run:
|
||||||
|
```bash
|
||||||
|
go run main.go
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Server settings can be modified in `main.go`:
|
||||||
|
```go
|
||||||
|
const (
|
||||||
|
port = ":6969" // Port to listen on
|
||||||
|
tickRate = 600 * time.Millisecond // Server tick rate
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Protocol
|
||||||
|
|
||||||
|
The server uses Protocol Buffers for client-server communication. The protocol is defined in `actions/actions.proto`:
|
||||||
|
|
||||||
|
- `Action`: Player actions (movement, chat)
|
||||||
|
- `ActionBatch`: Grouped actions from a player
|
||||||
|
- `ServerMessage`: Game state updates to clients
|
||||||
|
- `PlayerState`: Individual player state
|
||||||
|
- `ChatMessage`: Player chat messages
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
After modifying the protocol (`actions.proto`), regenerate the Go code:
|
||||||
|
```bash
|
||||||
|
protoc --go_out=. actions/actions.proto
|
||||||
|
```
|
||||||
|
|
||||||
|
## Deployment
|
||||||
|
|
||||||
|
The server is designed to run on a single instance. For production deployment:
|
||||||
|
|
||||||
|
1. Build the binary:
|
||||||
|
```bash
|
||||||
|
go build -o goonserver
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Run with logging:
|
||||||
|
```bash
|
||||||
|
./goonserver > server.log 2>&1 &
|
||||||
|
```
|
6
main.go
6
main.go
@ -154,8 +154,10 @@ func processActions() {
|
|||||||
currentTick := time.Now().UnixNano() / int64(tickRate)
|
currentTick := time.Now().UnixNano() / int64(tickRate)
|
||||||
state := &pb.ServerMessage{
|
state := &pb.ServerMessage{
|
||||||
CurrentTick: currentTick,
|
CurrentTick: currentTick,
|
||||||
|
Players: make([]*pb.PlayerState, 0, len(players)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert players to PlayerState
|
||||||
for id, p := range players {
|
for id, p := range players {
|
||||||
p.Lock()
|
p.Lock()
|
||||||
state.Players = append(state.Players, &pb.PlayerState{
|
state.Players = append(state.Players, &pb.PlayerState{
|
||||||
@ -166,9 +168,9 @@ func processActions() {
|
|||||||
p.Unlock()
|
p.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add chat messages to the server message
|
// Add new chat messages to the state
|
||||||
chatMutex.RLock()
|
chatMutex.RLock()
|
||||||
state.ChatMessages = chatHistory
|
state.ChatMessages = chatHistory[max(0, len(chatHistory)-5):] // Only send last 5 messages
|
||||||
chatMutex.RUnlock()
|
chatMutex.RUnlock()
|
||||||
|
|
||||||
data, err := proto.Marshal(state)
|
data, err := proto.Marshal(state)
|
||||||
|
Reference in New Issue
Block a user