// LOGIC

        public void Initialize()
        {
            m_Controller = WiFiInputUtilities.checkForClient <ButtonControllerType>(controlName, (int)playerNumber);
        }
        // WiFiServerController's interface

        public override void OnConnectionsChanged()
        {
            m_Controller = WiFiInputUtilities.checkForClient <ButtonControllerType>(controlName, (int)playerNumber);
        }
Beispiel #3
0
        //this method is responsible for registering a control which will instance a specific controller type
        //add it to the data structure and set its key and return it
        //There are two ways this method is called, one on the client the UI script in its startup registers it client side
        //The second way is the server when a client sends over its inventory
        public static string registerControl(string type, string name, string IP = "0")
        {
            BaseControllerType controller;
            string             key = "";

            switch (type)
            {
            case WiFiInputConstants.CONTROLLERTYPE_AXIS:
                controller = new AxisControllerType();
                controller.controllerType = WiFiInputConstants.CONTROLLERTYPE_AXIS;
                break;

            case WiFiInputConstants.CONTROLLERTYPE_BUTTON:
                controller = new ButtonControllerType();
                controller.controllerType = WiFiInputConstants.CONTROLLERTYPE_BUTTON;
                break;

            default:
                //should not occur
                controller = null;
                Debug.Log("Error: a controller type that isn't defined was registered");
                break;
            }

            controller.serverKey              = IP + name;
            controller.clientKey              = name;
            controller.clientIP               = IP;
            controller.logicalPlayerNumber    = getNewPlayerNumber(name);
            controller.lastReceivedPacketTime = DateTime.UtcNow;
            lastConnectedPlayerNumber         = controller.logicalPlayerNumber;
            isConnect = true;
            key       = controller.serverKey;

            if (!controllerDataDictionary.ContainsKey(key))
            {
                //brand new first time here
                controllerDataDictionary.Add(key, controller);
                controllerDataDictionaryKeys.Add(key);
                isNew = true;
            }
            else if (controllerDataDictionary[key].logicalPlayerNumber == WiFiInputConstants.PLAYERNUMBER_DISCONNECTED)
            {
                //already here just reassign (original disconnected and new one is here)
                //we will only change the player number if it's been occupied in between
                controllerDataDictionary[key].lastReceivedPacketTime = DateTime.UtcNow;
                controllerDataDictionary[key].justReconnected        = true;
                if (!WiFiInputUtilities.isPlayerNumberOccupied(controllerDataDictionary[key].previousConnectionPlayerNumber, controllerDataDictionary[key].clientKey))
                {
                    //not occupied assign it's previous number
                    controllerDataDictionary[key].logicalPlayerNumber = controllerDataDictionary[key].previousConnectionPlayerNumber;
                }
                else
                {
                    //occupied give it the lowest available number
                    controllerDataDictionary[key].logicalPlayerNumber = controller.logicalPlayerNumber;
                }
                isNew = true;
            }
            else
            {
                //was already here and isn't currently marked as disconnected (most likely a delayed packet)
                isNew = false;
            }

            if (isNew)
            {
                if (OnControllerRegisteredEvent != null)
                {
                    OnControllerRegisteredEvent(key);
                }
            }

            return(key);
        }