Пример #1
0
        //This method looks through the data structure and scans for timedout connections
        public static void checkForClientTimeout(float timeout)
        {
            BaseControllerType temp;
            bool foundDeadConnection = false;

            if (EasyWiFiController.controllerDataDictionary != null)
            {
                foreach (string key in EasyWiFiController.controllerDataDictionary.Keys)
                {
                    temp = EasyWiFiController.controllerDataDictionary[key];
                    if (!temp.controllerType.Contains(EasyWiFiConstants.BACKCHANNEL_FILTER) && temp.logicalPlayerNumber != EasyWiFiConstants.PLAYERNUMBER_DISCONNECTED && (DateTime.UtcNow - temp.lastReceivedPacketTime).TotalSeconds > timeout && (DateTime.UtcNow - temp.lastReceivedPacketTime).TotalSeconds < 150d)
                    {
                        temp.previousConnectionPlayerNumber = temp.logicalPlayerNumber;
                        temp.logicalPlayerNumber            = EasyWiFiConstants.PLAYERNUMBER_DISCONNECTED;
                        foundDeadConnection = true;
                        EasyWiFiController.lastConnectedPlayerNumber = temp.previousConnectionPlayerNumber;
                    }
                }
            }

            //if we found a dead connection let the callback know
            if (foundDeadConnection)
            {
                EasyWiFiController.isConnect = false;
                EasyWiFiController.forceConnectionRefresh();
            }
        }
Пример #2
0
        public static void createAndSendBackchannelMessages(int packetNumber)
        {
            List <string>      keys = new List <string>(controllerDataDictionary.Keys);
            BaseControllerType temp;



            //double loop because we are creating one message for each client
            foreach (string client in serverSendKeys)
            {
                bool   send    = false;
                string message = EasyWiFiConstants.MESSAGETYPE_BACKCHANNEL_DATA + EasyWiFiConstants.SPLITMESSAGE_COLON + packetNumber.ToString() + EasyWiFiConstants.SPLITMESSAGE_COLON;
                string append;

                foreach (string key in keys)
                {
                    temp = controllerDataDictionary[key];

                    if (temp.clientIP.Equals(client) && temp.controllerType.Contains(EasyWiFiConstants.BACKCHANNEL_FILTER) && temp.logicalPlayerNumber != EasyWiFiConstants.PLAYERNUMBER_DISCONNECTED)
                    {
                        append = temp.mapStructureToNetworkData();
                        if (append != null && !append.Equals(String.Empty))
                        {
                            send     = true;
                            message += temp.clientKey + EasyWiFiConstants.SPLITMESSAGE_POUND + append;
                        }
                    }
                }

                if (send)
                {
                    EasyWiFiController.sendWiFIBackchannelData(message, client);
                }
            }
        }
Пример #3
0
        public static void createAndSendHeartbeatMessages(int packetNumber)
        {
            BaseControllerType temp;

            //loop through each client
            foreach (string client in serverSendKeys)
            {
                bool   send    = true;
                string message = EasyWiFiConstants.MESSAGETYPE_HEARTBEAT + EasyWiFiConstants.SPLITMESSAGE_COLON + packetNumber.ToString();

                foreach (string key in controllerDataDictionary.Keys)
                {
                    temp = controllerDataDictionary[key];

                    if (temp.clientIP.Equals(client) && temp.logicalPlayerNumber == EasyWiFiConstants.PLAYERNUMBER_DISCONNECTED)
                    {
                        //we've found that this is actually disconnected
                        send = false;
                        break;
                    }
                }

                //we don't want to send heartbeat to those marked as disconnected
                if (send)
                {
                    EasyWiFiController.sendHeartbeat(message, client);
                }
            }
        }
        //for our network traffic on both ends we are essentially having strings (converted in/out for byte[] on the send/recieve
        //these methods essentially will be one line in the string (remember a client will have more than one controller type)



        //this method is called when a packet is received on a connection that is marked as disconnected due to a timeout
        //this can occur in game usecases when the player suspends the app and restarts and expects the controller to still work
        //because the app wasn't executing having the server sending a message stating hey you timed out is useless
        //instead because our design is player based simply check to see if another controller has been assigned this player number
        //if not then just change the player number back and proceed as normal
        //if another controller has then get the next available player number and then notify the callback of a changed connection
        public void reuseOrGetAnotherConnection(int previousPlayerNumber)
        {
            if (EasyWiFiUtilities.isPlayerNumberOccupied(previousPlayerNumber, clientKey))
            {
                logicalPlayerNumber = EasyWiFiController.getNewPlayerNumber(clientKey);
            }
            else
            {
                logicalPlayerNumber = previousConnectionPlayerNumber;
            }
            lastReceivedPacketTime = DateTime.UtcNow;
            justReconnected        = true;

            //take this time to reactivate all of the controls from this IP address so callback only get fired once
            BaseControllerType temp;

            string[] splitter = { clientKey };
            String[] clientIP = serverKey.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
            if (EasyWiFiController.controllerDataDictionary != null)
            {
                foreach (string key in EasyWiFiController.controllerDataDictionary.Keys)
                {
                    temp = EasyWiFiController.controllerDataDictionary[key];
                    if (temp.serverKey.Contains(clientIP[0]))
                    {
                        temp.justReconnected        = true;
                        temp.lastReceivedPacketTime = DateTime.UtcNow;
                        temp.logicalPlayerNumber    = logicalPlayerNumber;
                    }
                }
            }

            //send the callback for a connection
            EasyWiFiController.isConnect = true;
            EasyWiFiController.lastConnectedPlayerNumber = logicalPlayerNumber;
            EasyWiFiController.forceConnectionRefresh();
        }