From 95d52a88669f27701ce743c243afe68d0b145ff7 Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Sun, 3 May 2020 19:35:58 -0400 Subject: [PATCH] Client-side chat changes --- client/project.godot | 8 ++++ client/scenes/game.scn | Bin 1305 -> 1882 bytes client/scripts/network/NetworkManager.gd | 46 +++++++++++++++-------- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/client/project.godot b/client/project.godot index 11734e5..e36439a 100644 --- a/client/project.godot +++ b/client/project.godot @@ -24,6 +24,14 @@ config/icon="res://icon.png" MusicManager="*res://nodes/MusicManager.tscn" NetworkManager="*res://nodes/NetworkManager.tscn" +[input] + +send_chat_message={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777221,"unicode":0,"echo":false,"script":null) + ] +} + [rendering] environment/default_environment="res://default_env.tres" diff --git a/client/scenes/game.scn b/client/scenes/game.scn index 090f0cff1bcd9eb2776ddeb20e45a57a0edde7b6..e050f0f413f9db86873ead54b0a62c3b369a753b 100644 GIT binary patch literal 1882 zcmV-g2c`H@Q$s@n000005C8y(7XSd)1ONbM0ssIgwJ-f(01s^@0Je9tKrm~Z0A$+~ zSPBXX3JMAe3JMD1BUD60k`iWU+BTude1x&>$AJ{Y*|u3NrnQ2*A#Lo@|3tw71nR>R zL_8dU=S}?ID0uP4_D7r(yxU==0d8Bo`R0rr-o<@;N?hQ$F?vc1|FegkjqOgP@gkhI zX7H}3@%^~o^}GoK7}&#}Aq8c8|FwJgBQ1D6kyh?k@i!w_=hvVG)!X)efdAH;Hi!}S z1{f#&pG^O$KiW2NfLp+6unZqGl@<{h+LPl*P1Di7T_)^%+kQTLK^i_ezE|Er}(3L~33<80WYaS2vMOqdJ zl!;{1GVHP{YKr6%X(S3&Ii$)U01knWYaS2vMOqd7JArQx0EEUQ` zvS}H1Srs)!a%sw>k?5at=*Rq*-%_DWB%79DmsL^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4K!3@JiJTdAZyYfX34h;;@BmD{q5d!oa zGzA15wN?S=2bTI<{L?ewZ>B4eufa?1Z!kqs5T`L^Y`mPzmP1xZR3;`Km5)ia(`H0s zZ(V~^(rCP3`=uY?Uw(*+@ 0: - if ascii_data[0] == '1': - if ascii_data.substr(2,2) == "OK": - username = ascii_data.substr(4) - print("Logged in as: " + username) - emit_signal("logged_in") - else: - display_error("Username not accepted! Reason: " + ascii_data.substr(2)) - elif ascii_data[0] == '2': - world_data = ascii_data.substr(2) - emit_signal("world_data_recieved") + if event.get_channel_id() == 0: + var ascii_data : String = str(event.get_packet().get_string_from_ascii()) + if len(ascii_data) > 0: + if ascii_data[0] == '1': + if ascii_data.substr(2,2) == "OK": + username = ascii_data.substr(4) + print("Logged in as: " + username) + emit_signal("logged_in") + else: + display_error("Username not accepted! Reason: " + ascii_data.substr(2)) + elif ascii_data[0] == '2': + world_data = ascii_data.substr(2) + emit_signal("world_data_recieved") + elif event.get_channel_id() == 1: + var chat_message : String = str(event.get_packet().get_string_from_ascii()) + emit_signal("chat_message_recieved", chat_message) elif(event_type == GDNetEvent.CONNECT): print("Connected to server with hostname: " + server_address.get_host() + ":" + str(server_address.get_port())) connected = true @@ -96,16 +102,24 @@ func process_events(): connected = false emit_signal("disconnection") + +func send_chat_message(msg : String): + var pckt : PoolByteArray = (msg + '\n').to_ascii() + send_packet(pckt, 1) + +func send_packet(packet : PoolByteArray, channel = 0): + packetQueue.append({'channel':channel, 'packet' : packet}) + func move_player(x,y): var pckt : PoolByteArray = ("3|" + str(x) + "," + str(y)).to_ascii() - packetQueue.append(pckt) + send_packet(pckt) func _process(delta): process_events() if len(packetQueue) > 0 and connected: - peer.send_packet(packetQueue[0], 0, GDNetMessage.RELIABLE) + peer.send_packet(packetQueue[0]['packet'], packetQueue[0]['channel'], GDNetMessage.RELIABLE) packetQueue.remove(0)