Client-side chat changes
This commit is contained in:
parent
3b9e5d2ece
commit
95d52a8866
@ -24,6 +24,14 @@ config/icon="res://icon.png"
|
|||||||
MusicManager="*res://nodes/MusicManager.tscn"
|
MusicManager="*res://nodes/MusicManager.tscn"
|
||||||
NetworkManager="*res://nodes/NetworkManager.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]
|
[rendering]
|
||||||
|
|
||||||
environment/default_environment="res://default_env.tres"
|
environment/default_environment="res://default_env.tres"
|
||||||
|
Binary file not shown.
@ -10,6 +10,7 @@ signal error_occured
|
|||||||
signal logged_in
|
signal logged_in
|
||||||
|
|
||||||
signal world_data_recieved
|
signal world_data_recieved
|
||||||
|
signal chat_message_recieved
|
||||||
|
|
||||||
var username : String = ""
|
var username : String = ""
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ func _init():
|
|||||||
server_address = GDNetAddress.new()
|
server_address = GDNetAddress.new()
|
||||||
|
|
||||||
client = GDNetHost.new()
|
client = GDNetHost.new()
|
||||||
|
client.set_max_channels(2)
|
||||||
client.set_max_peers(1)
|
client.set_max_peers(1)
|
||||||
client.set_event_wait(250)
|
client.set_event_wait(250)
|
||||||
client.bind()
|
client.bind()
|
||||||
@ -52,13 +54,13 @@ func timeout_check():
|
|||||||
|
|
||||||
func request_world_map():
|
func request_world_map():
|
||||||
var request_packet : PoolByteArray = "2|".to_ascii()
|
var request_packet : PoolByteArray = "2|".to_ascii()
|
||||||
packetQueue.append(request_packet)
|
send_packet(request_packet)
|
||||||
|
|
||||||
func connect_as_user(username : String):
|
func connect_as_user(username : String):
|
||||||
connect_to_server()
|
connect_to_server()
|
||||||
var username_packet : PoolByteArray = ("1|" + username).to_ascii()
|
var username_packet : PoolByteArray = ("1|" + username).to_ascii()
|
||||||
|
|
||||||
packetQueue.append(username_packet)
|
send_packet(username_packet)
|
||||||
|
|
||||||
func display_error(error = "Unknown error occured!"):
|
func display_error(error = "Unknown error occured!"):
|
||||||
error_info = error
|
error_info = error
|
||||||
@ -75,18 +77,22 @@ func process_events():
|
|||||||
var event_type = event.get_event_type()
|
var event_type = event.get_event_type()
|
||||||
|
|
||||||
if(event_type == GDNetEvent.RECEIVE):
|
if(event_type == GDNetEvent.RECEIVE):
|
||||||
var ascii_data : String = str(event.get_packet().get_string_from_ascii())
|
if event.get_channel_id() == 0:
|
||||||
if len(ascii_data) > 0:
|
var ascii_data : String = str(event.get_packet().get_string_from_ascii())
|
||||||
if ascii_data[0] == '1':
|
if len(ascii_data) > 0:
|
||||||
if ascii_data.substr(2,2) == "OK":
|
if ascii_data[0] == '1':
|
||||||
username = ascii_data.substr(4)
|
if ascii_data.substr(2,2) == "OK":
|
||||||
print("Logged in as: " + username)
|
username = ascii_data.substr(4)
|
||||||
emit_signal("logged_in")
|
print("Logged in as: " + username)
|
||||||
else:
|
emit_signal("logged_in")
|
||||||
display_error("Username not accepted! Reason: " + ascii_data.substr(2))
|
else:
|
||||||
elif ascii_data[0] == '2':
|
display_error("Username not accepted! Reason: " + ascii_data.substr(2))
|
||||||
world_data = ascii_data.substr(2)
|
elif ascii_data[0] == '2':
|
||||||
emit_signal("world_data_recieved")
|
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):
|
elif(event_type == GDNetEvent.CONNECT):
|
||||||
print("Connected to server with hostname: " + server_address.get_host() + ":" + str(server_address.get_port()))
|
print("Connected to server with hostname: " + server_address.get_host() + ":" + str(server_address.get_port()))
|
||||||
connected = true
|
connected = true
|
||||||
@ -96,16 +102,24 @@ func process_events():
|
|||||||
connected = false
|
connected = false
|
||||||
emit_signal("disconnection")
|
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):
|
func move_player(x,y):
|
||||||
var pckt : PoolByteArray = ("3|" + str(x) + "," + str(y)).to_ascii()
|
var pckt : PoolByteArray = ("3|" + str(x) + "," + str(y)).to_ascii()
|
||||||
|
|
||||||
packetQueue.append(pckt)
|
send_packet(pckt)
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
process_events()
|
process_events()
|
||||||
|
|
||||||
if len(packetQueue) > 0 and connected:
|
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)
|
packetQueue.remove(0)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user