Compare commits
7 Commits
52ab45fe53
...
v1.1.1
Author | SHA1 | Date | |
---|---|---|---|
f9ec811b10 | |||
d25ee09155 | |||
e3c570349c | |||
27da845b11 | |||
3f7205d73e | |||
0731339fe8 | |||
71d42a8fd6 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.db
|
24
LICENSE
24
LICENSE
@ -1,11 +1,21 @@
|
|||||||
“Commons Clause” License Condition v1.0
|
MIT License
|
||||||
|
|
||||||
The Software is provided to you by the Licensor under the License, as defined below, subject to the following condition.
|
Copyright (c) 2025 bdnugget
|
||||||
|
|
||||||
Without limiting other conditions in the License, the grant of rights under the License will not include, and the License does not grant to you, right to Sell the Software.
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
For purposes of the foregoing, “Sell” means practicing any or all of the rights granted to you under the License to provide to third parties, for a fee or other consideration (including without limitation fees for hosting or consulting/ support services related to the Software), a product or service whose value derives, entirely or substantially, from the functionality of the Software. Any license notice or attribution required by the License must also include this Commons Cause License Condition notice.
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
Software: GoonServer (for Goonscape)
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
License: Commons Clause v1.0
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
Licensor: bdnugget
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
@ -168,12 +168,13 @@ func (x *Action) GetPassword() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ActionBatch struct {
|
type ActionBatch struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
PlayerId int32 `protobuf:"varint,1,opt,name=player_id,json=playerId,proto3" json:"player_id,omitempty"`
|
PlayerId int32 `protobuf:"varint,1,opt,name=player_id,json=playerId,proto3" json:"player_id,omitempty"`
|
||||||
Actions []*Action `protobuf:"bytes,2,rep,name=actions,proto3" json:"actions,omitempty"`
|
Actions []*Action `protobuf:"bytes,2,rep,name=actions,proto3" json:"actions,omitempty"`
|
||||||
Tick int64 `protobuf:"varint,3,opt,name=tick,proto3" json:"tick,omitempty"`
|
Tick int64 `protobuf:"varint,3,opt,name=tick,proto3" json:"tick,omitempty"`
|
||||||
unknownFields protoimpl.UnknownFields
|
ProtocolVersion int32 `protobuf:"varint,4,opt,name=protocol_version,json=protocolVersion,proto3" json:"protocol_version,omitempty"`
|
||||||
sizeCache protoimpl.SizeCache
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ActionBatch) Reset() {
|
func (x *ActionBatch) Reset() {
|
||||||
@ -227,11 +228,19 @@ func (x *ActionBatch) GetTick() int64 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *ActionBatch) GetProtocolVersion() int32 {
|
||||||
|
if x != nil {
|
||||||
|
return x.ProtocolVersion
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
type PlayerState struct {
|
type PlayerState struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
PlayerId int32 `protobuf:"varint,1,opt,name=player_id,json=playerId,proto3" json:"player_id,omitempty"`
|
PlayerId int32 `protobuf:"varint,1,opt,name=player_id,json=playerId,proto3" json:"player_id,omitempty"`
|
||||||
X int32 `protobuf:"varint,2,opt,name=x,proto3" json:"x,omitempty"`
|
X int32 `protobuf:"varint,2,opt,name=x,proto3" json:"x,omitempty"`
|
||||||
Y int32 `protobuf:"varint,3,opt,name=y,proto3" json:"y,omitempty"`
|
Y int32 `protobuf:"varint,3,opt,name=y,proto3" json:"y,omitempty"`
|
||||||
|
Username string `protobuf:"bytes,4,opt,name=username,proto3" json:"username,omitempty"`
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
@ -287,11 +296,19 @@ func (x *PlayerState) GetY() int32 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *PlayerState) GetUsername() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Username
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
type ChatMessage struct {
|
type ChatMessage struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
PlayerId int32 `protobuf:"varint,1,opt,name=player_id,json=playerId,proto3" json:"player_id,omitempty"`
|
PlayerId int32 `protobuf:"varint,1,opt,name=player_id,json=playerId,proto3" json:"player_id,omitempty"`
|
||||||
Content string `protobuf:"bytes,2,opt,name=content,proto3" json:"content,omitempty"`
|
Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"`
|
||||||
Timestamp int64 `protobuf:"varint,3,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
|
Content string `protobuf:"bytes,3,opt,name=content,proto3" json:"content,omitempty"`
|
||||||
|
Timestamp int64 `protobuf:"varint,4,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
@ -333,6 +350,13 @@ func (x *ChatMessage) GetPlayerId() int32 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *ChatMessage) GetUsername() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Username
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (x *ChatMessage) GetContent() string {
|
func (x *ChatMessage) GetContent() string {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Content
|
return x.Content
|
||||||
@ -348,15 +372,16 @@ func (x *ChatMessage) GetTimestamp() int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ServerMessage struct {
|
type ServerMessage struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
PlayerId int32 `protobuf:"varint,1,opt,name=player_id,json=playerId,proto3" json:"player_id,omitempty"`
|
PlayerId int32 `protobuf:"varint,1,opt,name=player_id,json=playerId,proto3" json:"player_id,omitempty"`
|
||||||
Players []*PlayerState `protobuf:"bytes,2,rep,name=players,proto3" json:"players,omitempty"`
|
Players []*PlayerState `protobuf:"bytes,2,rep,name=players,proto3" json:"players,omitempty"`
|
||||||
CurrentTick int64 `protobuf:"varint,3,opt,name=current_tick,json=currentTick,proto3" json:"current_tick,omitempty"`
|
CurrentTick int64 `protobuf:"varint,3,opt,name=current_tick,json=currentTick,proto3" json:"current_tick,omitempty"`
|
||||||
ChatMessages []*ChatMessage `protobuf:"bytes,4,rep,name=chat_messages,json=chatMessages,proto3" json:"chat_messages,omitempty"`
|
ChatMessages []*ChatMessage `protobuf:"bytes,4,rep,name=chat_messages,json=chatMessages,proto3" json:"chat_messages,omitempty"`
|
||||||
AuthSuccess bool `protobuf:"varint,5,opt,name=auth_success,json=authSuccess,proto3" json:"auth_success,omitempty"`
|
AuthSuccess bool `protobuf:"varint,5,opt,name=auth_success,json=authSuccess,proto3" json:"auth_success,omitempty"`
|
||||||
ErrorMessage string `protobuf:"bytes,6,opt,name=error_message,json=errorMessage,proto3" json:"error_message,omitempty"`
|
ErrorMessage string `protobuf:"bytes,6,opt,name=error_message,json=errorMessage,proto3" json:"error_message,omitempty"`
|
||||||
unknownFields protoimpl.UnknownFields
|
ProtocolVersion int32 `protobuf:"varint,7,opt,name=protocol_version,json=protocolVersion,proto3" json:"protocol_version,omitempty"`
|
||||||
sizeCache protoimpl.SizeCache
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ServerMessage) Reset() {
|
func (x *ServerMessage) Reset() {
|
||||||
@ -431,6 +456,13 @@ func (x *ServerMessage) GetErrorMessage() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *ServerMessage) GetProtocolVersion() int32 {
|
||||||
|
if x != nil {
|
||||||
|
return x.ProtocolVersion
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
var File_actions_proto protoreflect.FileDescriptor
|
var File_actions_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
var file_actions_proto_rawDesc = []byte{
|
var file_actions_proto_rawDesc = []byte{
|
||||||
@ -453,44 +485,53 @@ var file_actions_proto_rawDesc = []byte{
|
|||||||
0x08, 0x0a, 0x04, 0x43, 0x48, 0x41, 0x54, 0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x44, 0x49, 0x53,
|
0x08, 0x0a, 0x04, 0x43, 0x48, 0x41, 0x54, 0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x44, 0x49, 0x53,
|
||||||
0x43, 0x4f, 0x4e, 0x4e, 0x45, 0x43, 0x54, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x4c, 0x4f, 0x47,
|
0x43, 0x4f, 0x4e, 0x4e, 0x45, 0x43, 0x54, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x4c, 0x4f, 0x47,
|
||||||
0x49, 0x4e, 0x10, 0x03, 0x12, 0x0c, 0x0a, 0x08, 0x52, 0x45, 0x47, 0x49, 0x53, 0x54, 0x45, 0x52,
|
0x49, 0x4e, 0x10, 0x03, 0x12, 0x0c, 0x0a, 0x08, 0x52, 0x45, 0x47, 0x49, 0x53, 0x54, 0x45, 0x52,
|
||||||
0x10, 0x04, 0x22, 0x69, 0x0a, 0x0b, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x61, 0x74, 0x63,
|
0x10, 0x04, 0x22, 0x94, 0x01, 0x0a, 0x0b, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x61, 0x74,
|
||||||
0x68, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01,
|
0x63, 0x68, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18,
|
||||||
0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x49, 0x64, 0x12, 0x29,
|
0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x49, 0x64, 0x12,
|
||||||
0x0a, 0x07, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32,
|
0x29, 0x0a, 0x07, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b,
|
||||||
0x0f, 0x2e, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e,
|
0x32, 0x0f, 0x2e, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x41, 0x63, 0x74, 0x69, 0x6f,
|
||||||
0x52, 0x07, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x69, 0x63,
|
0x6e, 0x52, 0x07, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x69,
|
||||||
0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x69, 0x63, 0x6b, 0x22, 0x46, 0x0a,
|
0x63, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x69, 0x63, 0x6b, 0x12, 0x29,
|
||||||
0x0b, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x1b, 0x0a, 0x09,
|
0x0a, 0x10, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69,
|
||||||
|
0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63,
|
||||||
|
0x6f, 0x6c, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x62, 0x0a, 0x0b, 0x50, 0x6c, 0x61,
|
||||||
|
0x79, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x6c, 0x61, 0x79,
|
||||||
|
0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x70, 0x6c, 0x61,
|
||||||
|
0x79, 0x65, 0x72, 0x49, 0x64, 0x12, 0x0c, 0x0a, 0x01, 0x78, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05,
|
||||||
|
0x52, 0x01, 0x78, 0x12, 0x0c, 0x0a, 0x01, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01,
|
||||||
|
0x79, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20,
|
||||||
|
0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x7e, 0x0a,
|
||||||
|
0x0b, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1b, 0x0a, 0x09,
|
||||||
0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52,
|
0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52,
|
||||||
0x08, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x49, 0x64, 0x12, 0x0c, 0x0a, 0x01, 0x78, 0x18, 0x02,
|
0x08, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65,
|
||||||
0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x78, 0x12, 0x0c, 0x0a, 0x01, 0x79, 0x18, 0x03, 0x20, 0x01,
|
0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65,
|
||||||
0x28, 0x05, 0x52, 0x01, 0x79, 0x22, 0x62, 0x0a, 0x0b, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73,
|
0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74,
|
||||||
0x73, 0x61, 0x67, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x5f, 0x69,
|
0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12,
|
||||||
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x49,
|
0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x04, 0x20, 0x01,
|
||||||
0x64, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01,
|
0x28, 0x03, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0xad, 0x02,
|
||||||
0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x74,
|
0x0a, 0x0d, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12,
|
||||||
0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09,
|
0x1b, 0x0a, 0x09, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01,
|
||||||
0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x22, 0x82, 0x02, 0x0a, 0x0d, 0x53, 0x65,
|
0x28, 0x05, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x49, 0x64, 0x12, 0x2e, 0x0a, 0x07,
|
||||||
0x72, 0x76, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x70,
|
0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e,
|
||||||
0x6c, 0x61, 0x79, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08,
|
0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x53, 0x74,
|
||||||
0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x49, 0x64, 0x12, 0x2e, 0x0a, 0x07, 0x70, 0x6c, 0x61, 0x79,
|
0x61, 0x74, 0x65, 0x52, 0x07, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x12, 0x21, 0x0a, 0x0c,
|
||||||
0x65, 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x61, 0x63, 0x74, 0x69,
|
0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x74, 0x69, 0x63, 0x6b, 0x18, 0x03, 0x20, 0x01,
|
||||||
0x6f, 0x6e, 0x73, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52,
|
0x28, 0x03, 0x52, 0x0b, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x54, 0x69, 0x63, 0x6b, 0x12,
|
||||||
0x07, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x75, 0x72, 0x72,
|
0x39, 0x0a, 0x0d, 0x63, 0x68, 0x61, 0x74, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73,
|
||||||
0x65, 0x6e, 0x74, 0x5f, 0x74, 0x69, 0x63, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b,
|
0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73,
|
||||||
0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x54, 0x69, 0x63, 0x6b, 0x12, 0x39, 0x0a, 0x0d, 0x63,
|
0x2e, 0x43, 0x68, 0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x0c, 0x63, 0x68,
|
||||||
0x68, 0x61, 0x74, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x18, 0x04, 0x20, 0x03,
|
0x61, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x75,
|
||||||
0x28, 0x0b, 0x32, 0x14, 0x2e, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x43, 0x68, 0x61,
|
0x74, 0x68, 0x5f, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08,
|
||||||
0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x0c, 0x63, 0x68, 0x61, 0x74, 0x4d, 0x65,
|
0x52, 0x0b, 0x61, 0x75, 0x74, 0x68, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x12, 0x23, 0x0a,
|
||||||
0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x73,
|
0x0d, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x06,
|
||||||
0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x61, 0x75,
|
0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61,
|
||||||
0x74, 0x68, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x12, 0x23, 0x0a, 0x0d, 0x65, 0x72, 0x72,
|
0x67, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x5f, 0x76,
|
||||||
0x6f, 0x72, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09,
|
0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0f, 0x70, 0x72,
|
||||||
0x52, 0x0c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x42, 0x2c,
|
0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x42, 0x2c, 0x5a,
|
||||||
0x5a, 0x2a, 0x67, 0x69, 0x74, 0x65, 0x61, 0x2e, 0x62, 0x6f, 0x6e, 0x65, 0x72, 0x2e, 0x62, 0x65,
|
0x2a, 0x67, 0x69, 0x74, 0x65, 0x61, 0x2e, 0x62, 0x6f, 0x6e, 0x65, 0x72, 0x2e, 0x62, 0x65, 0x2f,
|
||||||
0x2f, 0x62, 0x64, 0x6e, 0x75, 0x67, 0x67, 0x65, 0x74, 0x2f, 0x67, 0x6f, 0x6f, 0x6e, 0x73, 0x65,
|
0x62, 0x64, 0x6e, 0x75, 0x67, 0x67, 0x65, 0x74, 0x2f, 0x67, 0x6f, 0x6f, 0x6e, 0x73, 0x65, 0x72,
|
||||||
0x72, 0x76, 0x65, 0x72, 0x2f, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x62, 0x06, 0x70, 0x72,
|
0x76, 0x65, 0x72, 0x2f, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f,
|
||||||
0x6f, 0x74, 0x6f, 0x33,
|
0x74, 0x6f, 0x33,
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -26,18 +26,21 @@ message ActionBatch {
|
|||||||
int32 player_id = 1;
|
int32 player_id = 1;
|
||||||
repeated Action actions = 2;
|
repeated Action actions = 2;
|
||||||
int64 tick = 3;
|
int64 tick = 3;
|
||||||
|
int32 protocol_version = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message PlayerState {
|
message PlayerState {
|
||||||
int32 player_id = 1;
|
int32 player_id = 1;
|
||||||
int32 x = 2;
|
int32 x = 2;
|
||||||
int32 y = 3;
|
int32 y = 3;
|
||||||
|
string username = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ChatMessage {
|
message ChatMessage {
|
||||||
int32 player_id = 1;
|
int32 player_id = 1;
|
||||||
string content = 2;
|
string username = 2;
|
||||||
int64 timestamp = 3;
|
string content = 3;
|
||||||
|
int64 timestamp = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ServerMessage {
|
message ServerMessage {
|
||||||
@ -47,4 +50,5 @@ message ServerMessage {
|
|||||||
repeated ChatMessage chat_messages = 4;
|
repeated ChatMessage chat_messages = 4;
|
||||||
bool auth_success = 5;
|
bool auth_success = 5;
|
||||||
string error_message = 6;
|
string error_message = 6;
|
||||||
|
int32 protocol_version = 7;
|
||||||
}
|
}
|
||||||
|
66
db/db.go
66
db/db.go
@ -5,6 +5,8 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
@ -17,6 +19,64 @@ var (
|
|||||||
ErrInvalidCredentials = errors.New("invalid username or password")
|
ErrInvalidCredentials = errors.New("invalid username or password")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
maxRegistrationsPerIP = 3 // Maximum registrations allowed per IP
|
||||||
|
registrationWindow = 24 * time.Hour // Time window for rate limiting
|
||||||
|
)
|
||||||
|
|
||||||
|
type registrationAttempt struct {
|
||||||
|
count int
|
||||||
|
firstTry time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
registrationAttempts = make(map[string]*registrationAttempt)
|
||||||
|
rateLimitMutex sync.RWMutex
|
||||||
|
)
|
||||||
|
|
||||||
|
func CleanupOldAttempts() {
|
||||||
|
rateLimitMutex.Lock()
|
||||||
|
defer rateLimitMutex.Unlock()
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
for ip, attempt := range registrationAttempts {
|
||||||
|
if now.Sub(attempt.firstTry) > registrationWindow {
|
||||||
|
delete(registrationAttempts, ip)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CheckRegistrationLimit(ip string) error {
|
||||||
|
rateLimitMutex.Lock()
|
||||||
|
defer rateLimitMutex.Unlock()
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
attempt, exists := registrationAttempts[ip]
|
||||||
|
|
||||||
|
if !exists {
|
||||||
|
registrationAttempts[ip] = ®istrationAttempt{
|
||||||
|
count: 1,
|
||||||
|
firstTry: now,
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset if window has passed
|
||||||
|
if now.Sub(attempt.firstTry) > registrationWindow {
|
||||||
|
attempt.count = 1
|
||||||
|
attempt.firstTry = now
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if attempt.count >= maxRegistrationsPerIP {
|
||||||
|
return fmt.Errorf("registration limit reached for this IP. Please try again in %v",
|
||||||
|
registrationWindow-now.Sub(attempt.firstTry))
|
||||||
|
}
|
||||||
|
|
||||||
|
attempt.count++
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func InitDB(dbPath string) error {
|
func InitDB(dbPath string) error {
|
||||||
var err error
|
var err error
|
||||||
db, err = sql.Open("sqlite3", dbPath)
|
db, err = sql.Open("sqlite3", dbPath)
|
||||||
@ -120,3 +180,9 @@ func LoadPlayerState(playerID int) (x, y int, err error) {
|
|||||||
}
|
}
|
||||||
return x, y, err
|
return x, y, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetUsername(playerID int) (string, error) {
|
||||||
|
var username string
|
||||||
|
err := db.QueryRow("SELECT username FROM players WHERE id = ?", playerID).Scan(&username)
|
||||||
|
return username, err
|
||||||
|
}
|
||||||
|
BIN
goonserver.db
BIN
goonserver.db
Binary file not shown.
135
main.go
135
main.go
@ -17,24 +17,25 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
port = ":6969" // Port to listen on
|
port = ":6969" // Port to listen on
|
||||||
tickRate = 600 * time.Millisecond
|
tickRate = 600 * time.Millisecond
|
||||||
|
protoVersion = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
type Player struct {
|
type Player struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
ID int
|
ID int
|
||||||
X, Y int // Position on the game grid
|
X, Y int
|
||||||
|
Username string
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
players = make(map[int]*Player)
|
players = make(map[int]*Player)
|
||||||
actionQueue = make(map[int][]*pb.Action) // Queue to store actions for each player
|
actionQueue = make(map[int][]*pb.Action) // Queue to store actions for each player
|
||||||
playerConns = make(map[int]net.Conn) // Map to store player connections
|
playerConns = make(map[int]net.Conn) // Map to store player connections
|
||||||
mu sync.RWMutex // Add mutex for protecting shared maps
|
mu sync.RWMutex // Add mutex for protecting shared maps
|
||||||
chatHistory = make([]*pb.ChatMessage, 0, 100)
|
chatHistory = make([]*pb.ChatMessage, 0, 100)
|
||||||
chatMutex sync.RWMutex
|
chatMutex sync.RWMutex
|
||||||
nextPlayerID = 1 // Assuming player IDs start from 1
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -53,6 +54,15 @@ func main() {
|
|||||||
ticker := time.NewTicker(tickRate)
|
ticker := time.NewTicker(tickRate)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
// Start registration attempt cleanup goroutine
|
||||||
|
go func() {
|
||||||
|
ticker := time.NewTicker(time.Hour)
|
||||||
|
defer ticker.Stop()
|
||||||
|
for range ticker.C {
|
||||||
|
db.CleanupOldAttempts()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Handle incoming connections in a separate goroutine
|
// Handle incoming connections in a separate goroutine
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
@ -74,6 +84,14 @@ func main() {
|
|||||||
func handleConnection(conn net.Conn) {
|
func handleConnection(conn net.Conn) {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
|
// Get client IP
|
||||||
|
remoteAddr := conn.RemoteAddr().String()
|
||||||
|
ip, _, err := net.SplitHostPort(remoteAddr)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to parse remote address: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Read initial message for player ID
|
// Read initial message for player ID
|
||||||
reader := bufio.NewReader(conn)
|
reader := bufio.NewReader(conn)
|
||||||
|
|
||||||
@ -106,8 +124,36 @@ func handleConnection(conn net.Conn) {
|
|||||||
var playerID int
|
var playerID int
|
||||||
var authErr error
|
var authErr error
|
||||||
|
|
||||||
|
if batch.ProtocolVersion == 0 {
|
||||||
|
response := &pb.ServerMessage{
|
||||||
|
AuthSuccess: false,
|
||||||
|
ErrorMessage: "Client using outdated protocol (pre-versioning)",
|
||||||
|
ProtocolVersion: protoVersion,
|
||||||
|
}
|
||||||
|
writeMessage(conn, response)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if batch.ProtocolVersion < protoVersion {
|
||||||
|
response := &pb.ServerMessage{
|
||||||
|
AuthSuccess: false,
|
||||||
|
ErrorMessage: fmt.Sprintf("Client protocol version too old (client: %d, required: %d)", batch.ProtocolVersion, protoVersion),
|
||||||
|
ProtocolVersion: protoVersion,
|
||||||
|
}
|
||||||
|
writeMessage(conn, response)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
switch action.Type {
|
switch action.Type {
|
||||||
case pb.Action_REGISTER:
|
case pb.Action_REGISTER:
|
||||||
|
if err := db.CheckRegistrationLimit(ip); err != nil {
|
||||||
|
response := &pb.ServerMessage{
|
||||||
|
AuthSuccess: false,
|
||||||
|
ErrorMessage: err.Error(),
|
||||||
|
}
|
||||||
|
writeMessage(conn, response)
|
||||||
|
return
|
||||||
|
}
|
||||||
playerID, authErr = db.RegisterPlayer(action.Username, action.Password)
|
playerID, authErr = db.RegisterPlayer(action.Username, action.Password)
|
||||||
case pb.Action_LOGIN:
|
case pb.Action_LOGIN:
|
||||||
playerID, authErr = db.AuthenticatePlayer(action.Username, action.Password)
|
playerID, authErr = db.AuthenticatePlayer(action.Username, action.Password)
|
||||||
@ -136,22 +182,57 @@ func handleConnection(conn net.Conn) {
|
|||||||
x, y = 5, 5 // Default position
|
x, y = 5, 5 // Default position
|
||||||
}
|
}
|
||||||
|
|
||||||
player := &Player{
|
username, err := db.GetUsername(playerID)
|
||||||
ID: playerID,
|
if err != nil {
|
||||||
X: x,
|
log.Printf("Error getting username for player %d: %v", playerID, err)
|
||||||
Y: y,
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player := &Player{
|
||||||
|
ID: playerID,
|
||||||
|
X: x,
|
||||||
|
Y: y,
|
||||||
|
Username: username,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prevent multiple logins
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
|
for _, p := range players {
|
||||||
|
if p.Username == username {
|
||||||
|
mu.Unlock()
|
||||||
|
response := &pb.ServerMessage{
|
||||||
|
AuthSuccess: false,
|
||||||
|
ErrorMessage: "Account already logged in",
|
||||||
|
}
|
||||||
|
writeMessage(conn, response)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
players[playerID] = player
|
players[playerID] = player
|
||||||
playerConns[playerID] = conn
|
playerConns[playerID] = conn
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
|
|
||||||
|
// Send initial state with correct position
|
||||||
|
response = &pb.ServerMessage{
|
||||||
|
PlayerId: int32(playerID),
|
||||||
|
AuthSuccess: true,
|
||||||
|
Players: []*pb.PlayerState{{
|
||||||
|
PlayerId: int32(playerID),
|
||||||
|
X: int32(x),
|
||||||
|
Y: int32(y),
|
||||||
|
Username: username,
|
||||||
|
}},
|
||||||
|
ProtocolVersion: protoVersion,
|
||||||
|
}
|
||||||
|
|
||||||
|
addSystemMessage(fmt.Sprintf("%s connected", username))
|
||||||
|
|
||||||
// Ensure player state is saved on any kind of disconnect
|
// Ensure player state is saved on any kind of disconnect
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := db.SavePlayerState(playerID, player.X, player.Y); err != nil {
|
if err := db.SavePlayerState(playerID, player.X, player.Y); err != nil {
|
||||||
log.Printf("Error saving state for player %d: %v", playerID, err)
|
log.Printf("Error saving state for player %d: %v", playerID, err)
|
||||||
}
|
}
|
||||||
|
addSystemMessage(fmt.Sprintf("%s disconnected", player.Username))
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
delete(players, playerID)
|
delete(players, playerID)
|
||||||
delete(playerConns, playerID)
|
delete(playerConns, playerID)
|
||||||
@ -209,11 +290,34 @@ func handleConnection(conn net.Conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func addChatMessage(playerID int32, content string) {
|
func addChatMessage(playerID int32, content string) {
|
||||||
|
player, exists := players[int(playerID)]
|
||||||
|
if !exists {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
chatMutex.Lock()
|
chatMutex.Lock()
|
||||||
defer chatMutex.Unlock()
|
defer chatMutex.Unlock()
|
||||||
|
|
||||||
msg := &pb.ChatMessage{
|
msg := &pb.ChatMessage{
|
||||||
PlayerId: playerID,
|
PlayerId: playerID,
|
||||||
|
Username: player.Username,
|
||||||
|
Content: content,
|
||||||
|
Timestamp: time.Now().UnixNano(),
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(chatHistory) >= 100 {
|
||||||
|
chatHistory = chatHistory[1:]
|
||||||
|
}
|
||||||
|
chatHistory = append(chatHistory, msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func addSystemMessage(content string) {
|
||||||
|
chatMutex.Lock()
|
||||||
|
defer chatMutex.Unlock()
|
||||||
|
|
||||||
|
msg := &pb.ChatMessage{
|
||||||
|
PlayerId: 0, // System messages use ID 0
|
||||||
|
Username: "System",
|
||||||
Content: content,
|
Content: content,
|
||||||
Timestamp: time.Now().UnixNano(),
|
Timestamp: time.Now().UnixNano(),
|
||||||
}
|
}
|
||||||
@ -261,6 +365,7 @@ func processActions() {
|
|||||||
PlayerId: int32(id),
|
PlayerId: int32(id),
|
||||||
X: int32(p.X),
|
X: int32(p.X),
|
||||||
Y: int32(p.Y),
|
Y: int32(p.Y),
|
||||||
|
Username: p.Username,
|
||||||
})
|
})
|
||||||
p.Unlock()
|
p.Unlock()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user