From 44c0a998ee1bc6b3ea5bec70259530695a30739d Mon Sep 17 00:00:00 2001 From: Mihai Moldovanu Date: Thu, 17 Mar 2022 02:35:43 +0200 Subject: [PATCH 1/2] Testing review --- TODO.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TODO.md b/TODO.md index ae6f509..33f14c8 100644 --- a/TODO.md +++ b/TODO.md @@ -13,3 +13,5 @@ * /set buy item * /set sell item * /get wanted + +## Things for web interface From e0015b6d738e35a0c10ac74600861ce9e019050a Mon Sep 17 00:00:00 2001 From: Mihai Moldovanu Date: Mon, 21 Mar 2022 05:04:21 +0200 Subject: [PATCH 2/2] Refactor pingReply --- main.go | 14 ++------------ sending.go | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/main.go b/main.go index 41f53c6..5b7abb7 100644 --- a/main.go +++ b/main.go @@ -154,8 +154,6 @@ func processPmMessage(c net.Conn, user string, mesaj string) { func processBuffer(c net.Conn, buffer []byte, length int) { - ping_reply := make([]byte, 7) - switch buffer[0] { // received inventory @@ -173,16 +171,8 @@ func processBuffer(c net.Conn, buffer []byte, length int) { // Ping from server case PING_REQUEST: a := int(buffer[1]) + 256*int(buffer[2]) - ping_reply[0] = buffer[0] - ping_reply[1] = buffer[1] - ping_reply[2] = buffer[2] - ping_reply[3] = buffer[3] - ping_reply[4] = buffer[4] - ping_reply[5] = buffer[5] - ping_reply[6] = buffer[6] - fmt.Printf("->Command: %d %d PING_REQUEST\n", buffer[0], a) - binary.Write(c, binary.LittleEndian, ping_reply) + sendPingReply(c, buffer) // text message received case RAW_TEXT: @@ -404,7 +394,7 @@ func main() { inventar = append(inventar, *v1) } - binary.Write(c, binary.LittleEndian, sendLogin(configuration.Credential.User, configuration.Credential.Password)) + sendLogin(c, configuration.Credential.User, configuration.Credential.Password) sec := time.Now().Unix() diff --git a/sending.go b/sending.go index 9029993..15f5035 100644 --- a/sending.go +++ b/sending.go @@ -2,13 +2,11 @@ package main import ( "encoding/binary" - "encoding/hex" - "fmt" "net" ) /* login to El */ -func sendLogin(user string, password string) []byte { +func sendLogin(c net.Conn, user string, password string) { s := user + " " + password lungime := len(s) + 3 b := make([]byte, lungime+2) @@ -17,7 +15,20 @@ func sendLogin(user string, password string) []byte { b[2] = byte(lungime / 256) copy(b[3:], s) b[lungime+1] = 0 - return b + binary.Write(c, binary.LittleEndian, b) +} + +/* Send back to server what we received */ +func sendPingReply(c net.Conn, b []byte) { + ping_reply := make([]byte, 7) + ping_reply[0] = b[0] + ping_reply[1] = b[1] + ping_reply[2] = b[2] + ping_reply[3] = b[3] + ping_reply[4] = b[4] + ping_reply[5] = b[5] + ping_reply[6] = b[6] + binary.Write(c, binary.LittleEndian, ping_reply) } func sendMessage(c net.Conn, user string, mesaj string) { @@ -56,7 +67,8 @@ func sendTrade(c net.Conn, actor int) { msg[4] = byte(actor / 256) msg[5] = 0 msg[6] = 0 - fmt.Printf("Send trade hex dump: %s\n", hex.Dump(msg)) + // @TODO@ - Add proper debug statement + // fmt.Printf("Send trade hex dump: %s\n", hex.Dump(msg)) binary.Write(c, binary.LittleEndian, msg) }