1
0
mirror of https://github.com/JohnBreaux/Boat-Battle.git synced 2024-11-15 05:25:57 +00:00

Multiplayer: Fix mail system

This commit is contained in:
John 2021-11-22 23:17:27 -06:00
parent 47c2acdada
commit 0ef058339c

View File

@ -5,12 +5,13 @@ const LOCALHOST = "127.0.0.1"
signal incoming signal incoming
# Let's pretend this is actually passed from send to receive
class Mail: class Mail:
var from # Sender address
var from:int
var message var message
var type var type:int
func _init(f, m, t): enum {FROM, MESSAGE, TYPE}
from = f; message = m; type = t
enum {REPLY, REQUEST} enum {REPLY, REQUEST}
# Store peer info in a dictionary, by player ID # Store peer info in a dictionary, by player ID
@ -27,16 +28,17 @@ var inbox = []
# Network -- handles server and client setup, and facilitates communication between the two # Network -- handles server and client setup, and facilitates communication between the two
# receive: Called when an incoming message is received # receive: Called when an incoming message is received
# item: The message received from the sender # item: The message received from the sender
remote func receive(mail:Mail): sync func receive(mail):
# Get the sender's ID and force letter to be properly addressed # Get the sender's ID and force letter to be properly addressed
mail.from = get_tree().get_rpc_sender_id() mail[0] = get_tree().get_rpc_sender_id()
print_debug(mail.from, mail.message, mail.type) # Add the mail to the inbox (so it can be read back later if necessary
inbox.append(mail)
# Sent it off to anything that expects mail # Sent it off to anything that expects mail
emit_signal("incoming", mail) emit_signal("incoming", mail)
func send(id, mail:Mail): func send(id, mail):
# Make the recipient receive the mail # Make the recipient receive the mail
rpc_id(id, "receive", mail) rpc_id(id, "receive", to_json(mail))
# start_server: Host the game # start_server: Host the game
# port: TCP port # port: TCP port