Slapping in the mix.

This commit is contained in:
2024-12-12 07:12:46 -05:00
parent ad6a061e5a
commit 913d5e93d4
7 changed files with 601 additions and 139 deletions

View File

@@ -49,6 +49,7 @@ func (c *Client) SendBuffer(conn net.Conn, buf []byte) {
func (c *Client) ReadData(callback func(*pb.ServerEnvelope)) { func (c *Client) ReadData(callback func(*pb.ServerEnvelope)) {
if c.connected {
for { for {
lengthBuf := make([]byte, 4) lengthBuf := make([]byte, 4)
_, err := io.ReadFull(c.conn, lengthBuf) _, err := io.ReadFull(c.conn, lengthBuf)
@@ -78,6 +79,7 @@ func (c *Client) ReadData(callback func(*pb.ServerEnvelope)) {
} }
} }
}
} }

View File

@@ -3,6 +3,7 @@ package elements
import ( import (
"client/gamedata" "client/gamedata"
"image/color" "image/color"
"math"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
) )
@@ -11,6 +12,7 @@ type Block struct {
Sprite *ebiten.Image Sprite *ebiten.Image
cycle int cycle int
position gamedata.Coordinates position gamedata.Coordinates
target gamedata.Coordinates
hit bool hit bool
} }
@@ -22,6 +24,17 @@ func NewBlock() *Block {
} }
func (b *Block) Update() { func (b *Block) Update() {
dx := b.target.X - b.position.X
dy := b.target.Y - b.position.Y
delta := math.Sqrt(dx*dx + dy*dy)
angle := math.Atan2(dy, dx)
if delta > 0.5 {
b.position.X += delta * math.Cos(angle) / 2
b.position.Y += delta * math.Sin(angle) / 2
}
b.cycle++ b.cycle++
} }
@@ -42,6 +55,14 @@ func (b *Block) GetPosition() gamedata.Coordinates {
return b.position return b.position
} }
func (b *Block) SetTargetPosition(pos gamedata.Coordinates) {
b.target = pos
}
func (b *Block) GetTargetosition() gamedata.Coordinates {
return b.target
}
func (b *Block) SetHit(hit bool) { func (b *Block) SetHit(hit bool) {
b.hit = hit b.hit = hit
} }

View File

@@ -8,10 +8,12 @@ import (
"client/pb" "client/pb"
"fmt" "fmt"
"maps" "maps"
"math"
"sync" "sync"
"time" "time"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/hajimehoshi/ebiten/v2/text/v2" "github.com/hajimehoshi/ebiten/v2/text/v2"
"golang.org/x/exp/rand" "golang.org/x/exp/rand"
) )
@@ -21,7 +23,13 @@ var (
screenHeight = 480 screenHeight = 480
movementLimit = 5 movementLimit = 5
namelist = []string{"slappy", "mick", "rodney", "george", "ringo", "robin", "temitry "} namelist = []string{"slappy", "mick", "rodney", "george", "ringo",
"robin", "temitry", "evangeline", "ron", "abigail", "lester",
"maynard", "agnes", "stacey", "wendell", "susanne", "myrtle",
"teresa", "kristi", "genos", "felton", "lawrence", "rosie",
"nigel", "constance", "maryellen", "dollie", "markus",
"dorthy", "lazaro", "willa", "dino", "gustavo", "conrad",
"georgia", "lucinda", "saitama"}
) )
func init() { func init() {
@@ -59,6 +67,7 @@ func NewGame() *Game {
g.hitblocky.SetHit(true) g.hitblocky.SetHit(true)
g.blocky.SetPosition(gamedata.Coordinates{X: float64(screenWidth) / 2, Y: float64(screenHeight) / 2}) g.blocky.SetPosition(gamedata.Coordinates{X: float64(screenWidth) / 2, Y: float64(screenHeight) / 2})
g.blocky.SetTargetPosition(gamedata.Coordinates{X: float64(screenWidth) / 2, Y: float64(screenHeight) / 2})
g.realclients = make(map[int]ClientData) g.realclients = make(map[int]ClientData)
@@ -69,29 +78,11 @@ func NewGame() *Game {
func (g *Game) Update() error { func (g *Game) Update() error {
g.blocky.Update()
//g.hitblocky.Update()
g.HandleInput() g.HandleInput()
g.SendPosition()
//broadcast our position
//if g.cycle%2 == 0 {
if g.gameclient.IsConnected() {
cd := &pb.ClientCoordinates{
Name: g.name,
Coordinates: &pb.Coordinates{
X: g.blocky.GetPosition().X, //g.position.X,
Y: g.blocky.GetPosition().Y, //g.position.Y,
},
}
envelope := &pb.ClientEnvelope{
Payload: &pb.ClientEnvelope_Coordinates{
Coordinates: cd,
},
}
g.gameclient.SendMessage(envelope)
}
//}
g.cycle++ g.cycle++
return nil return nil
@@ -180,8 +171,39 @@ func (g *Game) HandleServerData(envelope *pb.ServerEnvelope) {
delete(g.realclients, int(payload.Event.Id)) delete(g.realclients, int(payload.Event.Id))
} }
case *pb.ServerEnvelope_Identity: case *pb.ServerEnvelope_Identity:
fmt.Println("Server is trying to give us our id.") fmt.Println("Server is trying to give us our id: ", payload.Identity.Id)
g.gameId = int(payload.Identity.Id) g.gameId = int(payload.Identity.Id)
case *pb.ServerEnvelope_Gameevent:
fmt.Printf("someone slapping! target:%d, instigator:%d isSlap:%d", payload.Gameevent.Target, payload.Gameevent.Instigator, payload.Gameevent.Slap)
if payload.Gameevent.Target == int32(g.gameId) {
g.mu.Lock()
dx := g.blocky.GetPosition().X - g.realclients[int(payload.Gameevent.Instigator)].Position.X
dy := g.blocky.GetPosition().Y - g.realclients[int(payload.Gameevent.Instigator)].Position.Y
g.mu.Unlock()
if dx != 0 {
dx = (dx / math.Abs(dx)) * 100
}
if dy != 0 {
dy = (dy / math.Abs(dy)) * 100
}
if dx == 0 && dy == 0 {
b := rand.Intn(2)
if b == 0 {
dx = 100
dy = 100
} else {
dx = -100
dy = -100
}
}
cpos := gamedata.Coordinates{}
cpos.X = g.blocky.GetPosition().X + dx
cpos.Y = g.blocky.GetPosition().Y + dy
g.blocky.SetTargetPosition(cpos)
}
} }
} }
@@ -201,8 +223,50 @@ func (g *Game) HandleInput() {
if ebiten.IsKeyPressed(ebiten.KeyD) { if ebiten.IsKeyPressed(ebiten.KeyD) {
dx = +movementLimit dx = +movementLimit
} }
cpos := g.blocky.GetPosition() cpos := g.blocky.GetPosition()
cpos.X += float64(dx) cpos.X += float64(dx)
cpos.Y += float64(dy) cpos.Y += float64(dy)
g.blocky.SetPosition(cpos) g.blocky.SetTargetPosition(cpos)
if inpututil.IsKeyJustPressed(ebiten.KeySpace) {
g.SendSlap()
}
}
func (g *Game) SendPosition() {
//broadcast our position
if g.gameclient.IsConnected() {
cd := &pb.ClientCoordinates{
Name: g.name,
Coordinates: &pb.Coordinates{
X: g.blocky.GetPosition().X, //g.position.X,
Y: g.blocky.GetPosition().Y, //g.position.Y,
},
}
envelope := &pb.ClientEnvelope{
Payload: &pb.ClientEnvelope_Coordinates{
Coordinates: cd,
},
}
g.gameclient.SendMessage(envelope)
}
}
func (g *Game) SendSlap() {
if g.gameclient.IsConnected() {
slap := &pb.SlapEvent{
Slap: true,
}
envelope := &pb.ClientEnvelope{
Payload: &pb.ClientEnvelope_Slap{
Slap: slap,
},
}
g.gameclient.SendMessage(envelope)
}
} }

View File

@@ -350,6 +350,7 @@ type ClientEnvelope struct {
// Types that are assignable to Payload: // Types that are assignable to Payload:
// //
// *ClientEnvelope_Coordinates // *ClientEnvelope_Coordinates
// *ClientEnvelope_Slap
Payload isClientEnvelope_Payload `protobuf_oneof:"Payload"` Payload isClientEnvelope_Payload `protobuf_oneof:"Payload"`
} }
@@ -397,6 +398,13 @@ func (x *ClientEnvelope) GetCoordinates() *ClientCoordinates {
return nil return nil
} }
func (x *ClientEnvelope) GetSlap() *SlapEvent {
if x, ok := x.GetPayload().(*ClientEnvelope_Slap); ok {
return x.Slap
}
return nil
}
type isClientEnvelope_Payload interface { type isClientEnvelope_Payload interface {
isClientEnvelope_Payload() isClientEnvelope_Payload()
} }
@@ -405,8 +413,59 @@ type ClientEnvelope_Coordinates struct {
Coordinates *ClientCoordinates `protobuf:"bytes,1,opt,name=coordinates,proto3,oneof"` Coordinates *ClientCoordinates `protobuf:"bytes,1,opt,name=coordinates,proto3,oneof"`
} }
type ClientEnvelope_Slap struct {
Slap *SlapEvent `protobuf:"bytes,2,opt,name=slap,proto3,oneof"`
}
func (*ClientEnvelope_Coordinates) isClientEnvelope_Payload() {} func (*ClientEnvelope_Coordinates) isClientEnvelope_Payload() {}
func (*ClientEnvelope_Slap) isClientEnvelope_Payload() {}
type SlapEvent struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Slap bool `protobuf:"varint,1,opt,name=Slap,proto3" json:"Slap,omitempty"`
}
func (x *SlapEvent) Reset() {
*x = SlapEvent{}
mi := &file_clientdata_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *SlapEvent) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SlapEvent) ProtoMessage() {}
func (x *SlapEvent) ProtoReflect() protoreflect.Message {
mi := &file_clientdata_proto_msgTypes[6]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SlapEvent.ProtoReflect.Descriptor instead.
func (*SlapEvent) Descriptor() ([]byte, []int) {
return file_clientdata_proto_rawDescGZIP(), []int{6}
}
func (x *SlapEvent) GetSlap() bool {
if x != nil {
return x.Slap
}
return false
}
type ClientEvent struct { type ClientEvent struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@@ -418,7 +477,7 @@ type ClientEvent struct {
func (x *ClientEvent) Reset() { func (x *ClientEvent) Reset() {
*x = ClientEvent{} *x = ClientEvent{}
mi := &file_clientdata_proto_msgTypes[6] mi := &file_clientdata_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@@ -430,7 +489,7 @@ func (x *ClientEvent) String() string {
func (*ClientEvent) ProtoMessage() {} func (*ClientEvent) ProtoMessage() {}
func (x *ClientEvent) ProtoReflect() protoreflect.Message { func (x *ClientEvent) ProtoReflect() protoreflect.Message {
mi := &file_clientdata_proto_msgTypes[6] mi := &file_clientdata_proto_msgTypes[7]
if x != nil { if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@@ -443,7 +502,7 @@ func (x *ClientEvent) ProtoReflect() protoreflect.Message {
// Deprecated: Use ClientEvent.ProtoReflect.Descriptor instead. // Deprecated: Use ClientEvent.ProtoReflect.Descriptor instead.
func (*ClientEvent) Descriptor() ([]byte, []int) { func (*ClientEvent) Descriptor() ([]byte, []int) {
return file_clientdata_proto_rawDescGZIP(), []int{6} return file_clientdata_proto_rawDescGZIP(), []int{7}
} }
func (x *ClientEvent) GetId() int32 { func (x *ClientEvent) GetId() int32 {
@@ -460,6 +519,67 @@ func (x *ClientEvent) GetConnected() bool {
return false return false
} }
type GameEvent struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Instigator int32 `protobuf:"varint,1,opt,name=Instigator,proto3" json:"Instigator,omitempty"`
Target int32 `protobuf:"varint,2,opt,name=Target,proto3" json:"Target,omitempty"`
Slap bool `protobuf:"varint,3,opt,name=Slap,proto3" json:"Slap,omitempty"`
}
func (x *GameEvent) Reset() {
*x = GameEvent{}
mi := &file_clientdata_proto_msgTypes[8]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GameEvent) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GameEvent) ProtoMessage() {}
func (x *GameEvent) ProtoReflect() protoreflect.Message {
mi := &file_clientdata_proto_msgTypes[8]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GameEvent.ProtoReflect.Descriptor instead.
func (*GameEvent) Descriptor() ([]byte, []int) {
return file_clientdata_proto_rawDescGZIP(), []int{8}
}
func (x *GameEvent) GetInstigator() int32 {
if x != nil {
return x.Instigator
}
return 0
}
func (x *GameEvent) GetTarget() int32 {
if x != nil {
return x.Target
}
return 0
}
func (x *GameEvent) GetSlap() bool {
if x != nil {
return x.Slap
}
return false
}
type ServerEnvelope struct { type ServerEnvelope struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@@ -470,12 +590,13 @@ type ServerEnvelope struct {
// *ServerEnvelope_Identity // *ServerEnvelope_Identity
// *ServerEnvelope_Broadcast // *ServerEnvelope_Broadcast
// *ServerEnvelope_Event // *ServerEnvelope_Event
// *ServerEnvelope_Gameevent
Payload isServerEnvelope_Payload `protobuf_oneof:"Payload"` Payload isServerEnvelope_Payload `protobuf_oneof:"Payload"`
} }
func (x *ServerEnvelope) Reset() { func (x *ServerEnvelope) Reset() {
*x = ServerEnvelope{} *x = ServerEnvelope{}
mi := &file_clientdata_proto_msgTypes[7] mi := &file_clientdata_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@@ -487,7 +608,7 @@ func (x *ServerEnvelope) String() string {
func (*ServerEnvelope) ProtoMessage() {} func (*ServerEnvelope) ProtoMessage() {}
func (x *ServerEnvelope) ProtoReflect() protoreflect.Message { func (x *ServerEnvelope) ProtoReflect() protoreflect.Message {
mi := &file_clientdata_proto_msgTypes[7] mi := &file_clientdata_proto_msgTypes[9]
if x != nil { if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@@ -500,7 +621,7 @@ func (x *ServerEnvelope) ProtoReflect() protoreflect.Message {
// Deprecated: Use ServerEnvelope.ProtoReflect.Descriptor instead. // Deprecated: Use ServerEnvelope.ProtoReflect.Descriptor instead.
func (*ServerEnvelope) Descriptor() ([]byte, []int) { func (*ServerEnvelope) Descriptor() ([]byte, []int) {
return file_clientdata_proto_rawDescGZIP(), []int{7} return file_clientdata_proto_rawDescGZIP(), []int{9}
} }
func (m *ServerEnvelope) GetPayload() isServerEnvelope_Payload { func (m *ServerEnvelope) GetPayload() isServerEnvelope_Payload {
@@ -531,6 +652,13 @@ func (x *ServerEnvelope) GetEvent() *ClientEvent {
return nil return nil
} }
func (x *ServerEnvelope) GetGameevent() *GameEvent {
if x, ok := x.GetPayload().(*ServerEnvelope_Gameevent); ok {
return x.Gameevent
}
return nil
}
type isServerEnvelope_Payload interface { type isServerEnvelope_Payload interface {
isServerEnvelope_Payload() isServerEnvelope_Payload()
} }
@@ -547,12 +675,18 @@ type ServerEnvelope_Event struct {
Event *ClientEvent `protobuf:"bytes,3,opt,name=event,proto3,oneof"` Event *ClientEvent `protobuf:"bytes,3,opt,name=event,proto3,oneof"`
} }
type ServerEnvelope_Gameevent struct {
Gameevent *GameEvent `protobuf:"bytes,4,opt,name=gameevent,proto3,oneof"`
}
func (*ServerEnvelope_Identity) isServerEnvelope_Payload() {} func (*ServerEnvelope_Identity) isServerEnvelope_Payload() {}
func (*ServerEnvelope_Broadcast) isServerEnvelope_Payload() {} func (*ServerEnvelope_Broadcast) isServerEnvelope_Payload() {}
func (*ServerEnvelope_Event) isServerEnvelope_Payload() {} func (*ServerEnvelope_Event) isServerEnvelope_Payload() {}
func (*ServerEnvelope_Gameevent) isServerEnvelope_Payload() {}
var File_clientdata_proto protoreflect.FileDescriptor var File_clientdata_proto protoreflect.FileDescriptor
var file_clientdata_proto_rawDesc = []byte{ var file_clientdata_proto_rawDesc = []byte{
@@ -581,33 +715,47 @@ var file_clientdata_proto_rawDesc = []byte{
0x6e, 0x74, 0x44, 0x61, 0x74, 0x61, 0x52, 0x07, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x6e, 0x74, 0x44, 0x61, 0x74, 0x61, 0x52, 0x07, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x73, 0x22,
0x20, 0x0a, 0x0e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x20, 0x0a, 0x0e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74,
0x79, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x49, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x49,
0x64, 0x22, 0x58, 0x0a, 0x0e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45, 0x6e, 0x76, 0x65, 0x6c, 0x64, 0x22, 0x7f, 0x0a, 0x0e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45, 0x6e, 0x76, 0x65, 0x6c,
0x6f, 0x70, 0x65, 0x12, 0x3b, 0x0a, 0x0b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x6f, 0x70, 0x65, 0x12, 0x3b, 0x0a, 0x0b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74,
0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e,
0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65,
0x73, 0x48, 0x00, 0x52, 0x0b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x73, 0x48, 0x00, 0x52, 0x0b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73,
0x42, 0x09, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x22, 0x3b, 0x0a, 0x0b, 0x43, 0x12, 0x25, 0x0a, 0x04, 0x73, 0x6c, 0x61, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f,
0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x53, 0x6c, 0x61, 0x70, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x48,
0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x43, 0x6f, 0x00, 0x52, 0x04, 0x73, 0x6c, 0x61, 0x70, 0x42, 0x09, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f,
0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x43, 0x61, 0x64, 0x22, 0x1f, 0x0a, 0x09, 0x53, 0x6c, 0x61, 0x70, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12,
0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x22, 0xac, 0x01, 0x0a, 0x0e, 0x53, 0x65, 0x72, 0x12, 0x0a, 0x04, 0x53, 0x6c, 0x61, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x53,
0x76, 0x65, 0x72, 0x45, 0x6e, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x65, 0x12, 0x32, 0x0a, 0x08, 0x69, 0x6c, 0x61, 0x70, 0x22, 0x3b, 0x0a, 0x0b, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45, 0x76, 0x65,
0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02,
0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x18,
0x69, 0x74, 0x79, 0x48, 0x00, 0x52, 0x08, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64,
0x30, 0x0a, 0x09, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x18, 0x02, 0x20, 0x01, 0x22, 0x57, 0x0a, 0x09, 0x47, 0x61, 0x6d, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1e, 0x0a,
0x28, 0x0b, 0x32, 0x10, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x41, 0x6c, 0x6c, 0x43, 0x6c, 0x69, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x69, 0x67, 0x61, 0x74, 0x6f, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28,
0x65, 0x6e, 0x74, 0x73, 0x48, 0x00, 0x52, 0x09, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x05, 0x52, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x69, 0x67, 0x61, 0x74, 0x6f, 0x72, 0x12, 0x16, 0x0a,
0x74, 0x12, 0x29, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x06, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x54,
0x32, 0x11, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45, 0x76, 0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x53, 0x6c, 0x61, 0x70, 0x18, 0x03, 0x20,
0x65, 0x6e, 0x74, 0x48, 0x00, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x42, 0x09, 0x0a, 0x07, 0x01, 0x28, 0x08, 0x52, 0x04, 0x53, 0x6c, 0x61, 0x70, 0x22, 0xdd, 0x01, 0x0a, 0x0e, 0x53, 0x65,
0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x2a, 0x56, 0x0a, 0x0b, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x76, 0x65, 0x72, 0x45, 0x6e, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x65, 0x12, 0x32, 0x0a, 0x08,
0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14,
0x50, 0x45, 0x5f, 0x42, 0x52, 0x4f, 0x41, 0x44, 0x43, 0x41, 0x53, 0x54, 0x10, 0x00, 0x12, 0x15, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e,
0x0a, 0x11, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x49, 0x44, 0x45, 0x4e, 0x54, 0x74, 0x69, 0x74, 0x79, 0x48, 0x00, 0x52, 0x08, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79,
0x49, 0x54, 0x59, 0x10, 0x01, 0x12, 0x18, 0x0a, 0x14, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59, 0x50, 0x12, 0x30, 0x0a, 0x09, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x18, 0x02, 0x20,
0x45, 0x5f, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x49, 0x4e, 0x41, 0x54, 0x45, 0x53, 0x10, 0x02, 0x42, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x41, 0x6c, 0x6c, 0x43, 0x6c,
0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x69, 0x65, 0x6e, 0x74, 0x73, 0x48, 0x00, 0x52, 0x09, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61,
0x73, 0x74, 0x12, 0x29, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28,
0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45,
0x76, 0x65, 0x6e, 0x74, 0x48, 0x00, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x2f, 0x0a,
0x09, 0x67, 0x61, 0x6d, 0x65, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x0f, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x47, 0x61, 0x6d, 0x65, 0x45, 0x76, 0x65, 0x6e,
0x74, 0x48, 0x00, 0x52, 0x09, 0x67, 0x61, 0x6d, 0x65, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x42, 0x09,
0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x2a, 0x56, 0x0a, 0x0b, 0x4d, 0x65, 0x73,
0x73, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x4d, 0x53, 0x47, 0x5f,
0x54, 0x59, 0x50, 0x45, 0x5f, 0x42, 0x52, 0x4f, 0x41, 0x44, 0x43, 0x41, 0x53, 0x54, 0x10, 0x00,
0x12, 0x15, 0x0a, 0x11, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x49, 0x44, 0x45,
0x4e, 0x54, 0x49, 0x54, 0x59, 0x10, 0x01, 0x12, 0x18, 0x0a, 0x14, 0x4d, 0x53, 0x47, 0x5f, 0x54,
0x59, 0x50, 0x45, 0x5f, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x49, 0x4e, 0x41, 0x54, 0x45, 0x53, 0x10,
0x02, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
} }
var ( var (
@@ -623,7 +771,7 @@ func file_clientdata_proto_rawDescGZIP() []byte {
} }
var file_clientdata_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_clientdata_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_clientdata_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_clientdata_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
var file_clientdata_proto_goTypes = []any{ var file_clientdata_proto_goTypes = []any{
(MessageType)(0), // 0: main.MessageType (MessageType)(0), // 0: main.MessageType
(*Coordinates)(nil), // 1: main.Coordinates (*Coordinates)(nil), // 1: main.Coordinates
@@ -632,22 +780,26 @@ var file_clientdata_proto_goTypes = []any{
(*AllClients)(nil), // 4: main.AllClients (*AllClients)(nil), // 4: main.AllClients
(*ClientIdentity)(nil), // 5: main.ClientIdentity (*ClientIdentity)(nil), // 5: main.ClientIdentity
(*ClientEnvelope)(nil), // 6: main.ClientEnvelope (*ClientEnvelope)(nil), // 6: main.ClientEnvelope
(*ClientEvent)(nil), // 7: main.ClientEvent (*SlapEvent)(nil), // 7: main.SlapEvent
(*ServerEnvelope)(nil), // 8: main.ServerEnvelope (*ClientEvent)(nil), // 8: main.ClientEvent
(*GameEvent)(nil), // 9: main.GameEvent
(*ServerEnvelope)(nil), // 10: main.ServerEnvelope
} }
var file_clientdata_proto_depIdxs = []int32{ var file_clientdata_proto_depIdxs = []int32{
1, // 0: main.ClientData.coordinates:type_name -> main.Coordinates 1, // 0: main.ClientData.coordinates:type_name -> main.Coordinates
1, // 1: main.ClientCoordinates.coordinates:type_name -> main.Coordinates 1, // 1: main.ClientCoordinates.coordinates:type_name -> main.Coordinates
2, // 2: main.AllClients.Clients:type_name -> main.ClientData 2, // 2: main.AllClients.Clients:type_name -> main.ClientData
3, // 3: main.ClientEnvelope.coordinates:type_name -> main.ClientCoordinates 3, // 3: main.ClientEnvelope.coordinates:type_name -> main.ClientCoordinates
5, // 4: main.ServerEnvelope.identity:type_name -> main.ClientIdentity 7, // 4: main.ClientEnvelope.slap:type_name -> main.SlapEvent
4, // 5: main.ServerEnvelope.broadcast:type_name -> main.AllClients 5, // 5: main.ServerEnvelope.identity:type_name -> main.ClientIdentity
7, // 6: main.ServerEnvelope.event:type_name -> main.ClientEvent 4, // 6: main.ServerEnvelope.broadcast:type_name -> main.AllClients
7, // [7:7] is the sub-list for method output_type 8, // 7: main.ServerEnvelope.event:type_name -> main.ClientEvent
7, // [7:7] is the sub-list for method input_type 9, // 8: main.ServerEnvelope.gameevent:type_name -> main.GameEvent
7, // [7:7] is the sub-list for extension type_name 9, // [9:9] is the sub-list for method output_type
7, // [7:7] is the sub-list for extension extendee 9, // [9:9] is the sub-list for method input_type
0, // [0:7] is the sub-list for field type_name 9, // [9:9] is the sub-list for extension type_name
9, // [9:9] is the sub-list for extension extendee
0, // [0:9] is the sub-list for field type_name
} }
func init() { file_clientdata_proto_init() } func init() { file_clientdata_proto_init() }
@@ -657,11 +809,13 @@ func file_clientdata_proto_init() {
} }
file_clientdata_proto_msgTypes[5].OneofWrappers = []any{ file_clientdata_proto_msgTypes[5].OneofWrappers = []any{
(*ClientEnvelope_Coordinates)(nil), (*ClientEnvelope_Coordinates)(nil),
(*ClientEnvelope_Slap)(nil),
} }
file_clientdata_proto_msgTypes[7].OneofWrappers = []any{ file_clientdata_proto_msgTypes[9].OneofWrappers = []any{
(*ServerEnvelope_Identity)(nil), (*ServerEnvelope_Identity)(nil),
(*ServerEnvelope_Broadcast)(nil), (*ServerEnvelope_Broadcast)(nil),
(*ServerEnvelope_Event)(nil), (*ServerEnvelope_Event)(nil),
(*ServerEnvelope_Gameevent)(nil),
} }
type x struct{} type x struct{}
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
@@ -669,7 +823,7 @@ func file_clientdata_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_clientdata_proto_rawDesc, RawDescriptor: file_clientdata_proto_rawDesc,
NumEnums: 1, NumEnums: 1,
NumMessages: 8, NumMessages: 10,
NumExtensions: 0, NumExtensions: 0,
NumServices: 0, NumServices: 0,
}, },

View File

@@ -14,6 +14,7 @@ message ClientData {
string Address = 2; string Address = 2;
string Name = 3; string Name = 3;
Coordinates coordinates = 4; Coordinates coordinates = 4;
bool hit = 5;
} }
message ClientCoordinates { message ClientCoordinates {
@@ -28,3 +29,41 @@ message AllClients{
message ClientIdentity{ message ClientIdentity{
int32 Id = 1; int32 Id = 1;
} }
message ClientEnvelope {
oneof Payload {
ClientCoordinates coordinates = 1;
SlapEvent slap = 2;
}
}
message SlapEvent {
bool Slap = 1;
}
message ClientEvent {
int32 Id = 1;
bool Connected = 2;
}
message GameEvent {
int32 Instigator = 1;
int32 Target = 2;
bool Slap = 3;
}
message ServerEnvelope {
oneof Payload {
ClientIdentity identity = 1;
AllClients broadcast = 2;
ClientEvent event = 3;
GameEvent gameevent = 4;
}
}
enum MessageType {
MSG_TYPE_BROADCAST = 0;
MSG_TYPE_IDENTITY = 1;
MSG_TYPE_COORDINATES = 2;
}

View File

@@ -350,6 +350,7 @@ type ClientEnvelope struct {
// Types that are assignable to Payload: // Types that are assignable to Payload:
// //
// *ClientEnvelope_Coordinates // *ClientEnvelope_Coordinates
// *ClientEnvelope_Slap
Payload isClientEnvelope_Payload `protobuf_oneof:"Payload"` Payload isClientEnvelope_Payload `protobuf_oneof:"Payload"`
} }
@@ -397,6 +398,13 @@ func (x *ClientEnvelope) GetCoordinates() *ClientCoordinates {
return nil return nil
} }
func (x *ClientEnvelope) GetSlap() *SlapEvent {
if x, ok := x.GetPayload().(*ClientEnvelope_Slap); ok {
return x.Slap
}
return nil
}
type isClientEnvelope_Payload interface { type isClientEnvelope_Payload interface {
isClientEnvelope_Payload() isClientEnvelope_Payload()
} }
@@ -405,8 +413,59 @@ type ClientEnvelope_Coordinates struct {
Coordinates *ClientCoordinates `protobuf:"bytes,1,opt,name=coordinates,proto3,oneof"` Coordinates *ClientCoordinates `protobuf:"bytes,1,opt,name=coordinates,proto3,oneof"`
} }
type ClientEnvelope_Slap struct {
Slap *SlapEvent `protobuf:"bytes,2,opt,name=slap,proto3,oneof"`
}
func (*ClientEnvelope_Coordinates) isClientEnvelope_Payload() {} func (*ClientEnvelope_Coordinates) isClientEnvelope_Payload() {}
func (*ClientEnvelope_Slap) isClientEnvelope_Payload() {}
type SlapEvent struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Slap bool `protobuf:"varint,1,opt,name=Slap,proto3" json:"Slap,omitempty"`
}
func (x *SlapEvent) Reset() {
*x = SlapEvent{}
mi := &file_clientdata_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *SlapEvent) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SlapEvent) ProtoMessage() {}
func (x *SlapEvent) ProtoReflect() protoreflect.Message {
mi := &file_clientdata_proto_msgTypes[6]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SlapEvent.ProtoReflect.Descriptor instead.
func (*SlapEvent) Descriptor() ([]byte, []int) {
return file_clientdata_proto_rawDescGZIP(), []int{6}
}
func (x *SlapEvent) GetSlap() bool {
if x != nil {
return x.Slap
}
return false
}
type ClientEvent struct { type ClientEvent struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@@ -418,7 +477,7 @@ type ClientEvent struct {
func (x *ClientEvent) Reset() { func (x *ClientEvent) Reset() {
*x = ClientEvent{} *x = ClientEvent{}
mi := &file_clientdata_proto_msgTypes[6] mi := &file_clientdata_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@@ -430,7 +489,7 @@ func (x *ClientEvent) String() string {
func (*ClientEvent) ProtoMessage() {} func (*ClientEvent) ProtoMessage() {}
func (x *ClientEvent) ProtoReflect() protoreflect.Message { func (x *ClientEvent) ProtoReflect() protoreflect.Message {
mi := &file_clientdata_proto_msgTypes[6] mi := &file_clientdata_proto_msgTypes[7]
if x != nil { if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@@ -443,7 +502,7 @@ func (x *ClientEvent) ProtoReflect() protoreflect.Message {
// Deprecated: Use ClientEvent.ProtoReflect.Descriptor instead. // Deprecated: Use ClientEvent.ProtoReflect.Descriptor instead.
func (*ClientEvent) Descriptor() ([]byte, []int) { func (*ClientEvent) Descriptor() ([]byte, []int) {
return file_clientdata_proto_rawDescGZIP(), []int{6} return file_clientdata_proto_rawDescGZIP(), []int{7}
} }
func (x *ClientEvent) GetId() int32 { func (x *ClientEvent) GetId() int32 {
@@ -460,6 +519,67 @@ func (x *ClientEvent) GetConnected() bool {
return false return false
} }
type GameEvent struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Instigator int32 `protobuf:"varint,1,opt,name=Instigator,proto3" json:"Instigator,omitempty"`
Target int32 `protobuf:"varint,2,opt,name=Target,proto3" json:"Target,omitempty"`
Slap bool `protobuf:"varint,3,opt,name=Slap,proto3" json:"Slap,omitempty"`
}
func (x *GameEvent) Reset() {
*x = GameEvent{}
mi := &file_clientdata_proto_msgTypes[8]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GameEvent) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GameEvent) ProtoMessage() {}
func (x *GameEvent) ProtoReflect() protoreflect.Message {
mi := &file_clientdata_proto_msgTypes[8]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GameEvent.ProtoReflect.Descriptor instead.
func (*GameEvent) Descriptor() ([]byte, []int) {
return file_clientdata_proto_rawDescGZIP(), []int{8}
}
func (x *GameEvent) GetInstigator() int32 {
if x != nil {
return x.Instigator
}
return 0
}
func (x *GameEvent) GetTarget() int32 {
if x != nil {
return x.Target
}
return 0
}
func (x *GameEvent) GetSlap() bool {
if x != nil {
return x.Slap
}
return false
}
type ServerEnvelope struct { type ServerEnvelope struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@@ -470,12 +590,13 @@ type ServerEnvelope struct {
// *ServerEnvelope_Identity // *ServerEnvelope_Identity
// *ServerEnvelope_Broadcast // *ServerEnvelope_Broadcast
// *ServerEnvelope_Event // *ServerEnvelope_Event
// *ServerEnvelope_Gameevent
Payload isServerEnvelope_Payload `protobuf_oneof:"Payload"` Payload isServerEnvelope_Payload `protobuf_oneof:"Payload"`
} }
func (x *ServerEnvelope) Reset() { func (x *ServerEnvelope) Reset() {
*x = ServerEnvelope{} *x = ServerEnvelope{}
mi := &file_clientdata_proto_msgTypes[7] mi := &file_clientdata_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi) ms.StoreMessageInfo(mi)
} }
@@ -487,7 +608,7 @@ func (x *ServerEnvelope) String() string {
func (*ServerEnvelope) ProtoMessage() {} func (*ServerEnvelope) ProtoMessage() {}
func (x *ServerEnvelope) ProtoReflect() protoreflect.Message { func (x *ServerEnvelope) ProtoReflect() protoreflect.Message {
mi := &file_clientdata_proto_msgTypes[7] mi := &file_clientdata_proto_msgTypes[9]
if x != nil { if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil { if ms.LoadMessageInfo() == nil {
@@ -500,7 +621,7 @@ func (x *ServerEnvelope) ProtoReflect() protoreflect.Message {
// Deprecated: Use ServerEnvelope.ProtoReflect.Descriptor instead. // Deprecated: Use ServerEnvelope.ProtoReflect.Descriptor instead.
func (*ServerEnvelope) Descriptor() ([]byte, []int) { func (*ServerEnvelope) Descriptor() ([]byte, []int) {
return file_clientdata_proto_rawDescGZIP(), []int{7} return file_clientdata_proto_rawDescGZIP(), []int{9}
} }
func (m *ServerEnvelope) GetPayload() isServerEnvelope_Payload { func (m *ServerEnvelope) GetPayload() isServerEnvelope_Payload {
@@ -531,6 +652,13 @@ func (x *ServerEnvelope) GetEvent() *ClientEvent {
return nil return nil
} }
func (x *ServerEnvelope) GetGameevent() *GameEvent {
if x, ok := x.GetPayload().(*ServerEnvelope_Gameevent); ok {
return x.Gameevent
}
return nil
}
type isServerEnvelope_Payload interface { type isServerEnvelope_Payload interface {
isServerEnvelope_Payload() isServerEnvelope_Payload()
} }
@@ -547,12 +675,18 @@ type ServerEnvelope_Event struct {
Event *ClientEvent `protobuf:"bytes,3,opt,name=event,proto3,oneof"` Event *ClientEvent `protobuf:"bytes,3,opt,name=event,proto3,oneof"`
} }
type ServerEnvelope_Gameevent struct {
Gameevent *GameEvent `protobuf:"bytes,4,opt,name=gameevent,proto3,oneof"`
}
func (*ServerEnvelope_Identity) isServerEnvelope_Payload() {} func (*ServerEnvelope_Identity) isServerEnvelope_Payload() {}
func (*ServerEnvelope_Broadcast) isServerEnvelope_Payload() {} func (*ServerEnvelope_Broadcast) isServerEnvelope_Payload() {}
func (*ServerEnvelope_Event) isServerEnvelope_Payload() {} func (*ServerEnvelope_Event) isServerEnvelope_Payload() {}
func (*ServerEnvelope_Gameevent) isServerEnvelope_Payload() {}
var File_clientdata_proto protoreflect.FileDescriptor var File_clientdata_proto protoreflect.FileDescriptor
var file_clientdata_proto_rawDesc = []byte{ var file_clientdata_proto_rawDesc = []byte{
@@ -581,33 +715,47 @@ var file_clientdata_proto_rawDesc = []byte{
0x6e, 0x74, 0x44, 0x61, 0x74, 0x61, 0x52, 0x07, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x6e, 0x74, 0x44, 0x61, 0x74, 0x61, 0x52, 0x07, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x73, 0x22,
0x20, 0x0a, 0x0e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x20, 0x0a, 0x0e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74,
0x79, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x49, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x49,
0x64, 0x22, 0x58, 0x0a, 0x0e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45, 0x6e, 0x76, 0x65, 0x6c, 0x64, 0x22, 0x7f, 0x0a, 0x0e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45, 0x6e, 0x76, 0x65, 0x6c,
0x6f, 0x70, 0x65, 0x12, 0x3b, 0x0a, 0x0b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x6f, 0x70, 0x65, 0x12, 0x3b, 0x0a, 0x0b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74,
0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e,
0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65,
0x73, 0x48, 0x00, 0x52, 0x0b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x73, 0x48, 0x00, 0x52, 0x0b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73,
0x42, 0x09, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x22, 0x3b, 0x0a, 0x0b, 0x43, 0x12, 0x25, 0x0a, 0x04, 0x73, 0x6c, 0x61, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f,
0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x53, 0x6c, 0x61, 0x70, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x48,
0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x43, 0x6f, 0x00, 0x52, 0x04, 0x73, 0x6c, 0x61, 0x70, 0x42, 0x09, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f,
0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x43, 0x61, 0x64, 0x22, 0x1f, 0x0a, 0x09, 0x53, 0x6c, 0x61, 0x70, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12,
0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x22, 0xac, 0x01, 0x0a, 0x0e, 0x53, 0x65, 0x72, 0x12, 0x0a, 0x04, 0x53, 0x6c, 0x61, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x53,
0x76, 0x65, 0x72, 0x45, 0x6e, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x65, 0x12, 0x32, 0x0a, 0x08, 0x69, 0x6c, 0x61, 0x70, 0x22, 0x3b, 0x0a, 0x0b, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45, 0x76, 0x65,
0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02,
0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x18,
0x69, 0x74, 0x79, 0x48, 0x00, 0x52, 0x08, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64,
0x30, 0x0a, 0x09, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x18, 0x02, 0x20, 0x01, 0x22, 0x57, 0x0a, 0x09, 0x47, 0x61, 0x6d, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1e, 0x0a,
0x28, 0x0b, 0x32, 0x10, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x41, 0x6c, 0x6c, 0x43, 0x6c, 0x69, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x69, 0x67, 0x61, 0x74, 0x6f, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28,
0x65, 0x6e, 0x74, 0x73, 0x48, 0x00, 0x52, 0x09, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x05, 0x52, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x69, 0x67, 0x61, 0x74, 0x6f, 0x72, 0x12, 0x16, 0x0a,
0x74, 0x12, 0x29, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x06, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x54,
0x32, 0x11, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45, 0x76, 0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x53, 0x6c, 0x61, 0x70, 0x18, 0x03, 0x20,
0x65, 0x6e, 0x74, 0x48, 0x00, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x42, 0x09, 0x0a, 0x07, 0x01, 0x28, 0x08, 0x52, 0x04, 0x53, 0x6c, 0x61, 0x70, 0x22, 0xdd, 0x01, 0x0a, 0x0e, 0x53, 0x65,
0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x2a, 0x56, 0x0a, 0x0b, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x72, 0x76, 0x65, 0x72, 0x45, 0x6e, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x65, 0x12, 0x32, 0x0a, 0x08,
0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14,
0x50, 0x45, 0x5f, 0x42, 0x52, 0x4f, 0x41, 0x44, 0x43, 0x41, 0x53, 0x54, 0x10, 0x00, 0x12, 0x15, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e,
0x0a, 0x11, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x49, 0x44, 0x45, 0x4e, 0x54, 0x74, 0x69, 0x74, 0x79, 0x48, 0x00, 0x52, 0x08, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79,
0x49, 0x54, 0x59, 0x10, 0x01, 0x12, 0x18, 0x0a, 0x14, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59, 0x50, 0x12, 0x30, 0x0a, 0x09, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x18, 0x02, 0x20,
0x45, 0x5f, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x49, 0x4e, 0x41, 0x54, 0x45, 0x53, 0x10, 0x02, 0x42, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x41, 0x6c, 0x6c, 0x43, 0x6c,
0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 0x69, 0x65, 0x6e, 0x74, 0x73, 0x48, 0x00, 0x52, 0x09, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61,
0x73, 0x74, 0x12, 0x29, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28,
0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45,
0x76, 0x65, 0x6e, 0x74, 0x48, 0x00, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x2f, 0x0a,
0x09, 0x67, 0x61, 0x6d, 0x65, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x0f, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x47, 0x61, 0x6d, 0x65, 0x45, 0x76, 0x65, 0x6e,
0x74, 0x48, 0x00, 0x52, 0x09, 0x67, 0x61, 0x6d, 0x65, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x42, 0x09,
0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x2a, 0x56, 0x0a, 0x0b, 0x4d, 0x65, 0x73,
0x73, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x4d, 0x53, 0x47, 0x5f,
0x54, 0x59, 0x50, 0x45, 0x5f, 0x42, 0x52, 0x4f, 0x41, 0x44, 0x43, 0x41, 0x53, 0x54, 0x10, 0x00,
0x12, 0x15, 0x0a, 0x11, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x49, 0x44, 0x45,
0x4e, 0x54, 0x49, 0x54, 0x59, 0x10, 0x01, 0x12, 0x18, 0x0a, 0x14, 0x4d, 0x53, 0x47, 0x5f, 0x54,
0x59, 0x50, 0x45, 0x5f, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x49, 0x4e, 0x41, 0x54, 0x45, 0x53, 0x10,
0x02, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
} }
var ( var (
@@ -623,7 +771,7 @@ func file_clientdata_proto_rawDescGZIP() []byte {
} }
var file_clientdata_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_clientdata_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_clientdata_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_clientdata_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
var file_clientdata_proto_goTypes = []any{ var file_clientdata_proto_goTypes = []any{
(MessageType)(0), // 0: main.MessageType (MessageType)(0), // 0: main.MessageType
(*Coordinates)(nil), // 1: main.Coordinates (*Coordinates)(nil), // 1: main.Coordinates
@@ -632,22 +780,26 @@ var file_clientdata_proto_goTypes = []any{
(*AllClients)(nil), // 4: main.AllClients (*AllClients)(nil), // 4: main.AllClients
(*ClientIdentity)(nil), // 5: main.ClientIdentity (*ClientIdentity)(nil), // 5: main.ClientIdentity
(*ClientEnvelope)(nil), // 6: main.ClientEnvelope (*ClientEnvelope)(nil), // 6: main.ClientEnvelope
(*ClientEvent)(nil), // 7: main.ClientEvent (*SlapEvent)(nil), // 7: main.SlapEvent
(*ServerEnvelope)(nil), // 8: main.ServerEnvelope (*ClientEvent)(nil), // 8: main.ClientEvent
(*GameEvent)(nil), // 9: main.GameEvent
(*ServerEnvelope)(nil), // 10: main.ServerEnvelope
} }
var file_clientdata_proto_depIdxs = []int32{ var file_clientdata_proto_depIdxs = []int32{
1, // 0: main.ClientData.coordinates:type_name -> main.Coordinates 1, // 0: main.ClientData.coordinates:type_name -> main.Coordinates
1, // 1: main.ClientCoordinates.coordinates:type_name -> main.Coordinates 1, // 1: main.ClientCoordinates.coordinates:type_name -> main.Coordinates
2, // 2: main.AllClients.Clients:type_name -> main.ClientData 2, // 2: main.AllClients.Clients:type_name -> main.ClientData
3, // 3: main.ClientEnvelope.coordinates:type_name -> main.ClientCoordinates 3, // 3: main.ClientEnvelope.coordinates:type_name -> main.ClientCoordinates
5, // 4: main.ServerEnvelope.identity:type_name -> main.ClientIdentity 7, // 4: main.ClientEnvelope.slap:type_name -> main.SlapEvent
4, // 5: main.ServerEnvelope.broadcast:type_name -> main.AllClients 5, // 5: main.ServerEnvelope.identity:type_name -> main.ClientIdentity
7, // 6: main.ServerEnvelope.event:type_name -> main.ClientEvent 4, // 6: main.ServerEnvelope.broadcast:type_name -> main.AllClients
7, // [7:7] is the sub-list for method output_type 8, // 7: main.ServerEnvelope.event:type_name -> main.ClientEvent
7, // [7:7] is the sub-list for method input_type 9, // 8: main.ServerEnvelope.gameevent:type_name -> main.GameEvent
7, // [7:7] is the sub-list for extension type_name 9, // [9:9] is the sub-list for method output_type
7, // [7:7] is the sub-list for extension extendee 9, // [9:9] is the sub-list for method input_type
0, // [0:7] is the sub-list for field type_name 9, // [9:9] is the sub-list for extension type_name
9, // [9:9] is the sub-list for extension extendee
0, // [0:9] is the sub-list for field type_name
} }
func init() { file_clientdata_proto_init() } func init() { file_clientdata_proto_init() }
@@ -657,11 +809,13 @@ func file_clientdata_proto_init() {
} }
file_clientdata_proto_msgTypes[5].OneofWrappers = []any{ file_clientdata_proto_msgTypes[5].OneofWrappers = []any{
(*ClientEnvelope_Coordinates)(nil), (*ClientEnvelope_Coordinates)(nil),
(*ClientEnvelope_Slap)(nil),
} }
file_clientdata_proto_msgTypes[7].OneofWrappers = []any{ file_clientdata_proto_msgTypes[9].OneofWrappers = []any{
(*ServerEnvelope_Identity)(nil), (*ServerEnvelope_Identity)(nil),
(*ServerEnvelope_Broadcast)(nil), (*ServerEnvelope_Broadcast)(nil),
(*ServerEnvelope_Event)(nil), (*ServerEnvelope_Event)(nil),
(*ServerEnvelope_Gameevent)(nil),
} }
type x struct{} type x struct{}
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
@@ -669,7 +823,7 @@ func file_clientdata_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_clientdata_proto_rawDesc, RawDescriptor: file_clientdata_proto_rawDesc,
NumEnums: 1, NumEnums: 1,
NumMessages: 8, NumMessages: 10,
NumExtensions: 0, NumExtensions: 0,
NumServices: 0, NumServices: 0,
}, },

View File

@@ -25,6 +25,8 @@ type ClientData struct {
Name string Name string
Position gamedata.Coordinates Position gamedata.Coordinates
Hit bool Hit bool
Target int
Slapping bool
} }
type Server struct { type Server struct {
@@ -124,6 +126,7 @@ func (s *Server) HandleClient(conn net.Conn, id int) {
Position: gamedata.Coordinates{X: payload.Coordinates.Coordinates.X, Y: payload.Coordinates.Coordinates.Y}, Position: gamedata.Coordinates{X: payload.Coordinates.Coordinates.X, Y: payload.Coordinates.Coordinates.Y},
} }
s.mu.Lock()
//check if we have any collisions with other entities //check if we have any collisions with other entities
for _, client := range s.clientlist { for _, client := range s.clientlist {
if client.Id != id { if client.Id != id {
@@ -133,15 +136,20 @@ func (s *Server) HandleClient(conn net.Conn, id int) {
if math.Abs(dx) < boxwidth && math.Abs(dy) < boxwidth { if math.Abs(dx) < boxwidth && math.Abs(dy) < boxwidth {
//collision, mark it //collision, mark it
cd.Hit = true cd.Hit = true
cd.Target = client.Id
} }
} }
} }
//update the client list //update the client list
s.mu.Lock()
s.clientlist[conn] = cd s.clientlist[conn] = cd
s.mu.Unlock() s.mu.Unlock()
case *pb.ClientEnvelope_Slap:
if s.clientlist[conn].Target != 0 && s.clientlist[conn].Hit {
s.BroadcastSlap(id, s.clientlist[conn].Target)
} else {
fmt.Println("Invalid slap detected.")
}
} }
} }
@@ -273,3 +281,23 @@ func (s *Server) SendClientEvent(conn net.Conn, id int, connected bool) {
s.mu.Unlock() s.mu.Unlock()
} }
func (s *Server) BroadcastSlap(instigator, target int) {
envelope := &pb.ServerEnvelope{
Payload: &pb.ServerEnvelope_Gameevent{
Gameevent: &pb.GameEvent{
Instigator: int32(instigator),
Target: int32(target),
Slap: true,
},
},
}
s.mu.Lock()
for conn := range s.clientlist {
s.SendMessage(conn, envelope)
}
s.mu.Unlock()
}