private void HandleRemoteConnect(NetworkClient <RelayClient> client, byte[] data)
 {
     lock (remoteRelays)
     {
         using (MessageReader mr = new MessageReader(data))
         {
             string[]       parents        = mr.Read <string[]>();
             int            serverID       = mr.Read <int>();
             string         serverIP       = mr.Read <string>();
             int            serverPort     = mr.Read <int>();
             RelayClient    relayClient    = GetRelayClient(parents);
             ReporterClient reporterClient = new ReporterClient();
             reporterClient.clientID   = serverID;
             reporterClient.remoteIP   = serverIP;
             reporterClient.remotePort = serverPort;
             //Add to DB
             Console.WriteLine("RELAY: Remote receiver connect from " + relayClient.relayHash + ", client: " + reporterClient.clientID);
             relayClient.remoteClients.Add(reporterClient.clientID, reporterClient);
             dbServer.Connect(relayClient.relayHash, reporterClient);
             //Relay
             string[] newParents = new string[parents.Length + 1];
             newParents[0] = settings.reporterHash;
             parents.CopyTo(newParents, 1);
             networkServer.QueueToOthers(client, new NetworkMessage((int)MessageType.REMOTE_CONNECT, GetRemoteConnectBytes(newParents, reporterClient)));
         }
     }
 }
 public void LocalReport(ReporterClient client, ReportingMessage reportMessage)
 {
     lock (localClients)
     {
         networkServer.QueueToAll(new NetworkMessage((int)MessageType.REMOTE_REPORT, GetRemoteReportBytes(new string[] { settings.reporterHash }, client, reportMessage)));
         dbServer.Report(settings.reporterHash, client, reportMessage);
     }
 }
 public void LocalDisconnect(ReporterClient client)
 {
     lock (localClients)
     {
         localClients.Remove(client.clientID);
         networkServer.QueueToAll(new NetworkMessage((int)MessageType.REMOTE_DISCONNECT, GetRemoteDisconnectBytes(new string[] { settings.reporterHash }, client)));
         dbServer.Disconnect(settings.reporterHash, client);
     }
 }
 private byte[] GetRemoteDisconnectBytes(string[] parents, ReporterClient reporterClient)
 {
     byte[] retVal;
     using (MessageWriter mw = new MessageWriter())
     {
         mw.Write <string[]>(parents);
         mw.Write <int>(reporterClient.clientID);
         retVal = mw.GetMessageBytes();
     }
     return(retVal);
 }
Ejemplo n.º 5
0
 private byte[] GetDisconnectMessageBytes(string serverID, ReporterClient client)
 {
     byte[] retBytes;
     using (MessageWriter mw = new MessageWriter())
     {
         mw.Write <string>(serverID);
         mw.Write <int>(client.clientID);
         retBytes = mw.GetMessageBytes();
     }
     return(retBytes);
 }
Ejemplo n.º 6
0
 private byte[] GetReportMessageBytes(string serverID, ReporterClient client, ReportingMessage reportMessage)
 {
     byte[] retBytes;
     using (MessageWriter mw = new MessageWriter())
     {
         mw.Write <string>(serverID);
         mw.Write <int>(client.clientID);
         mw.Write <byte[]>(reportMessage.GetBytes());
         retBytes = mw.GetMessageBytes();
     }
     return(retBytes);
 }
Ejemplo n.º 7
0
        public static string GetSafeGameAddress(string inputAddress, ReporterClient client)
        {
            //If there is only 1 ':' mark, they have probably incorrectly put the port after the game address. Let's cut it off.
            if (inputAddress.Contains(":") && inputAddress.IndexOf(":") == inputAddress.LastIndexOf(":"))
            {
                inputAddress = inputAddress.Substring(0, inputAddress.IndexOf(":"));
            }
            string    outputAddress = inputAddress;
            IPAddress parseAddress;
            bool      overrideAddress = false;

            if (inputAddress == "")
            {
                overrideAddress = true;
            }
            //Check that it's a valid IP address or DNS address.
            if (!IPAddress.TryParse(inputAddress, out parseAddress))
            {
                try
                {
                    IAsyncResult ar = Dns.BeginGetHostAddresses(inputAddress, null, null);
                    if (ar.AsyncWaitHandle.WaitOne(30000))
                    {
                        IPAddress[] addresses = Dns.EndGetHostAddresses(ar);
                        if (addresses.Length == 0)
                        {
                            overrideAddress = true;
                        }
                    }
                    else
                    {
                        overrideAddress = true;
                    }
                }
                catch
                {
                    overrideAddress = true;
                }
            }
            if (overrideAddress)
            {
                outputAddress = client.remoteIP;
            }
            return(outputAddress);
        }
 private void HandleRemoteDisconnect(NetworkClient <RelayClient> client, byte[] data)
 {
     lock (remoteRelays)
     {
         using (MessageReader mr = new MessageReader(data))
         {
             string[]       parents        = mr.Read <string[]>();
             int            serverID       = mr.Read <int>();
             RelayClient    relayClient    = GetRelayClient(parents);
             ReporterClient reporterClient = relayClient.remoteClients[serverID];
             RemoteDisconnect(relayClient, reporterClient);
             //Relay
             string[] newParents = new string[parents.Length + 1];
             newParents[0] = settings.reporterHash;
             parents.CopyTo(newParents, 1);
             networkServer.QueueToOthers(client, new NetworkMessage((int)MessageType.REMOTE_DISCONNECT, GetRemoteDisconnectBytes(newParents, reporterClient)));
         }
     }
 }
 private void HandleRemoteReport(NetworkClient <RelayClient> client, byte[] data)
 {
     lock (remoteRelays)
     {
         using (MessageReader mr = new MessageReader(data))
         {
             string[]         parents        = mr.Read <string[]>();
             int              serverID       = mr.Read <int>();
             byte[]           reportBytes    = mr.Read <byte[]>();
             RelayClient      relayClient    = GetRelayClient(parents);
             ReporterClient   reporterClient = relayClient.remoteClients[serverID];
             ReportingMessage reportMessage  = ReportingMessage.FromBytesBE(reportBytes);
             reporterClient.lastMessage = reportMessage;
             //Add to DB
             Console.WriteLine("RELAY: Remote receiver report from " + relayClient.relayHash + ", client: " + reporterClient.clientID + ", players: " + reportMessage.players.Length);
             dbServer.Report(relayClient.relayHash, reporterClient, reportMessage);
             //Relay
             string[] newParents = new string[parents.Length + 1];
             newParents[0] = settings.reporterHash;
             parents.CopyTo(newParents, 1);
             networkServer.QueueToOthers(client, new NetworkMessage((int)MessageType.REMOTE_REPORT, GetRemoteReportBytes(newParents, reporterClient, reportMessage)));
         }
     }
 }
 private void RemoteDisconnect(RelayClient parentClient, ReporterClient client)
 {
     Console.WriteLine("RELAY: Remote receiver disconnect from " + parentClient.relayHash + ", client: " + client.clientID);
     parentClient.remoteClients.Remove(client.clientID);
     dbServer.Disconnect(parentClient.relayHash, client);
 }
 private void HandleReport(ReporterClient client, ReportingMessage message)
 {
     client.lastMessage = message;
     Console.WriteLine("RECEIVER: Report from " + client.clientID + ", players: " + message.players.Length);
     relayServer.LocalReport(client, message);
 }
Ejemplo n.º 12
0
 public void Disconnect(string serverID, ReporterClient client)
 {
     networkServer.QueueToAll(new NetworkMessage((int)MessageType.DISCONNECT, GetDisconnectMessageBytes(serverID, client)));
 }
Ejemplo n.º 13
0
 public void Report(string serverID, ReporterClient client, ReportingMessage reportMessage)
 {
     networkServer.QueueToAll(new NetworkMessage((int)MessageType.REPORT, GetReportMessageBytes(serverID, client, reportMessage)));
 }