Skip to content

Commit

Permalink
#267 Fixed merged requests
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed May 15, 2023
1 parent f6a3e34 commit 1464d08
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
47 changes: 22 additions & 25 deletions pokete_classes/multiplayer/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,32 @@ def establish_connection(self):
)
return False

def send_pos_update(self, _map, x, y):
def send(self, data: dict):
self.connection.sendall(
str.encode(
json.dumps(
{
"Type": 0,
"Body": {
"Map": _map,
"X": x,
"Y": y,
},
}
)
)
str.encode(json.dumps(data)) + END_SECTION
)

def send_pos_update(self, _map, x, y):
self.send(
{
"Type": 0,
"Body": {
"Map": _map,
"X": x,
"Y": y,
},
}
)

def handshake(self):
self.connection.sendall(
str.encode(
json.dumps(
{
"Type": 1,
"Body": {
"UserName": self.user_name,
"Version": release.VERSION,
},
}
)
)
self.send(
{
"Type": 1,
"Body": {
"UserName": self.user_name,
"Version": release.VERSION,
},
}
)
if (d := self.receive_data())["Type"] == 2:
self.ask_user_name(True)
Expand Down
25 changes: 17 additions & 8 deletions server/server/server.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package server

import (
"github.com/lxgr-linux/pokete/server/provider"
"bytes"
"github.com/lxgr-linux/pokete/server/provider"
"log"
"net"

Expand All @@ -13,6 +14,10 @@ import (
"github.com/lxgr-linux/pokete/server/user_repository"
)

var (
END_SECTION = []byte("<END>")
)

func NewServer(cfg config.Config) (server Server, err error) {
mapRepo, err := map_repository.NewMapRepo()
if err != nil {
Expand Down Expand Up @@ -51,13 +56,17 @@ func (s Server) Start() {
}
}

func (s Server) handleRequests(res []byte, connection *net.Conn) error {
genericResponseObject, err := handler.Handle(res)
log.Printf("%#v\n", genericResponseObject)
err = genericResponseObject.Body.Handle(connection, s.Provider)
if err != nil {
return err
}
func (s Server) handleRequests(origRes []byte, connection *net.Conn) error {
splid := bytes.Split(origRes, END_SECTION)
for _, res := range splid[:len(splid) - 1]{
genericResponseObject, err := handler.Handle(res)
log.Printf("%s", res)
log.Printf("%#v\n", genericResponseObject)
err = genericResponseObject.Body.Handle(connection, s.Provider)
if err != nil {
return err
}
}
return nil
}

Expand Down

0 comments on commit 1464d08

Please sign in to comment.