3 Commits

Author SHA1 Message Date
a48fef0186 Only send last 5 chat messages 2025-01-15 10:36:36 +01:00
67e08c5d1e Readme 2025-01-13 15:12:16 +01:00
49e2311497 Merge pull request 'Implement chat' (#1) from feature/chat into master
Reviewed-on: #1
2025-01-13 13:15:25 +00:00
2 changed files with 79 additions and 2 deletions

75
README.md Normal file
View 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 &
```

View File

@ -154,8 +154,10 @@ func processActions() {
currentTick := time.Now().UnixNano() / int64(tickRate)
state := &pb.ServerMessage{
CurrentTick: currentTick,
Players: make([]*pb.PlayerState, 0, len(players)),
}
// Convert players to PlayerState
for id, p := range players {
p.Lock()
state.Players = append(state.Players, &pb.PlayerState{
@ -166,9 +168,9 @@ func processActions() {
p.Unlock()
}
// Add chat messages to the server message
// Add new chat messages to the state
chatMutex.RLock()
state.ChatMessages = chatHistory
state.ChatMessages = chatHistory[max(0, len(chatHistory)-5):] // Only send last 5 messages
chatMutex.RUnlock()
data, err := proto.Marshal(state)