public static void Send(byte[] data) { PTMessage msg = new PTMessage(); msg.senderName = playerName; msg.data = data; if (NetworkServer.active) { //Send to all clients if the sender is a TableTop foreach (PTPlayer player in Players) { Send(player, data); } } else if (singleton.myClient != null && singleton.myClient.isConnected) { //Send to connected TableTop if the sender is a Handheld if (singleton.myClient.connection != null) { singleton.myClient.Send((short)PTEvent.Data, msg); singleton.PTDebug("Sent to server: " + msg.ToString(true)); } else { singleton.PTDebug("PTManager Error: built-in client is Null"); } } }
void Handler_OnConfirmReady(NetworkMessage netMsg) { PTMessage msg = netMsg.ReadMessage <PTMessage>(); PTDebug("OnConfirmReady: " + msg.ToString(true)); if (OnConfirmReadyReceived != null) { OnConfirmReadyReceived(msg); } }
void Handler_OnReadyReceived(NetworkMessage netMsg) { PTMessage msg = netMsg.ReadMessage <PTMessage>(); PTDebug("OnReady: " + msg.ToString(true)); PTPlayer player = PTPlayer.Find(msg.senderName); if (player != null) { players[player] = true; } if (OnReadyReceived != null) { OnReadyReceived(msg); } ConfirmReadyReceived(netMsg); }
void Handler_OnConnected(NetworkMessage netMsg) { PTMessage msg = netMsg.ReadMessage <PTMessage>(); PTDebug("OnConnected: " + msg.ToString(true)); PTPlayer player = PTPlayer.Find(netMsg.conn.connectionId); if (player != null) { players[player] = false; } else { PTPlayer newPlayer = new PTPlayer(msg.senderName, netMsg.conn.connectionId, null); players.Add(newPlayer, false); } if (isTableTop) { if (!acceptNewPlayer || players.Count >= maximumPlayer) { //put the newly connected player in the wait queue KeyValuePair <string, int> newPlayer = new KeyValuePair <string, int>(msg.senderName, netMsg.conn.connectionId); waitQueue.Enqueue(newPlayer); } //Tell the sender client that this server has been connected PTMessage msgFromServer = new PTMessage(); msgFromServer.senderName = playerName; NetworkServer.SendToClient(netMsg.conn.connectionId, (short)PTEvent.Connect, msgFromServer); } else { } //Invoke OnConnected Event if (OnConnected != null) { OnConnected(msg); } }
public static void Send(PTPlayer player, byte[] data) { //This method is the parent method for other server side overloads //Corner case if (singleton == null || !NetworkServer.active || player == null) { Debug.Log("Error in PTManager.Send(PTPlayer player, byte[] data): Check singleton, server settings or PTPlayer instance"); return; } //create pt message to send PTMessage msg = new PTMessage(); msg.senderName = playerName; msg.data = data; //Send the pt message NetworkServer.SendToClient(player.connectionId, (short)PTEvent.Data, msg); singleton.PTDebug("Sent to " + player + ": " + msg.ToString(true)); }