Exemple #1
0
    private void OnClickStartNewServer()
    {
        if (_playerName != null && _playerName.Length > 0)
        {
            StartNewServerEvent SNSE;
            string ipAddress = FFClient.GetLocalIP().ToString();
            SNSE.serverIpAddress = System.Net.IPAddress.Parse(ipAddress);
            SNSE.serverName      = _playerName;
            FFMessage <StartNewServerEvent> .SendToLocal(SNSE);

#if UNITY_WEBPLAYER
            // Start + Connect to local Server
            FFServer.StartServer(80, _playerName + "'s Server", true);
            FFClient.StartClient(ipAddress, 80, _playerName);
#endif

#if UNITY_STANDALONE
            // Start + Connect to local Server
            FFServer.StartServer(6532, _playerName + "'s Server", true);
            FFClient.StartClient(ipAddress, 6532, _playerName);
#endif
            ChangeLevelStateEvent CLSE;
            CLSE.newState = LevelState.In_Game;
            FFMessage <ChangeLevelStateEvent> .SendToLocal(CLSE);
        }
        else
        {
            NoticeAddPlayerName();
        }
        Debug.Log("Clicked StartNewServer"); // debug
    }
Exemple #2
0
    private void OnClickJoinServer()
    {
        if (_serverIPAddress != null && _playerName != null && _playerName.Length > 0)
        {
            JoinServerEvent e;
            e.serverIpAddress = _serverIPAddress;
            e.playerName      = _playerName;
            FFMessage <JoinServerEvent> .SendToLocal(e);

            FFClient.StartClient(_serverIPAddress.ToString(), 6532, _playerName);

            ChangeLevelStateEvent CLSE;
            CLSE.newState = LevelState.In_Game;
            FFMessage <ChangeLevelStateEvent> .SendToLocal(CLSE);
        }
        else
        {
            if (_serverIPAddress == null)
            {
                NoticeValidIPAddress();
            }
            if (_playerName == null)
            {
                NoticeAddPlayerName();
            }
        }

        Debug.Log("Clicked JoinServer"); // debug
    }
        public static void SendToNet <EventType>(FFPacket <EventType> netPacket, bool varifiedPacket)
        {
            // any Data scrambling which is based on type needs to happen here. It is unscrambled
            // in
            FFPacket <EventType> .Encrypt(ref netPacket.message);

            FFClient.SendPacket(netPacket, varifiedPacket);
            return;
        }
Exemple #4
0
 private FFClient()
 {
     if (singleton != null)
     {
         Debug.LogError("Error created a second Singleton of FFNetServer");
         return;
     }
     _singleton = this;
 }
Exemple #5
0
    public static void GetReady()
    {
        if (singleton == null)
        {
            GameObject newFFClient;
            newFFClient = new GameObject("FFClient");
            _singleton  = newFFClient.AddComponent <FFClient>();
            FFMessage <ClientConnectedEvent> .Connect(OnClientConnected);

            FFMessage <ClientSyncTimeEvent> .Connect(OnClientSyncTime);
        }
    }
Exemple #6
0
    void OnDestroy()
    {
        Debug.Log("FFClient Destroyed");
        _singleton = null;
        EndSendThread();

        try
        {
            if (_clientData.clientSocketTCP != null && _clientData.clientSocketTCP.socket != null && _clientData.clientSocketTCP.socket.IsBound)
            {
                _clientData.clientSocketTCP.socket.BeginDisconnect(false, new AsyncCallback(DisconnectCallback), _clientData.clientSocketTCP.socket);
                _clientData.clientSocketTCP.socket     = null;
                _clientData.clientSocketTCP.clientData = null;
                _clientData.clientSocketTCP            = null;
            }
        }
        catch (Exception exp) { Debug.Log("Error in FFServer OnDestroy() : " + exp.Message); }

        try
        {
            if (_clientData.clientSocketUDP != null && _clientData.clientSocketUDP.udpClient != null)
            {
                _clientData.clientSocketUDP.udpClient.Close();
                _clientData.clientSocketUDP.udpClient         = null;
                _clientData.clientSocketUDP.udpEndPointLocal  = null;
                _clientData.clientSocketUDP.udpEndPointRemote = null;
                _clientData.clientSocketUDP.socket            = null;
                _clientData.clientSocketUDP.clientData        = null;
                _clientData.clientSocketUDP = null;
            }
        }
        catch (Exception exp) { Debug.Log("Error in FFServer OnDestroy() : " + exp.Message); }

        FFLocalEvents.TimeChangeEvent TCE;
        TCE.newCurrentTime = FFSystem.time;
        FFMessage <FFLocalEvents.TimeChangeEvent> .SendToLocal(TCE);

        FFMessage <ClientConnectedEvent> .Disconnect(OnClientConnected);

        FFMessage <ClientSyncTimeEvent> .Disconnect(OnClientSyncTime);
    }
Exemple #7
0
    public static void StartClient(string ipAddress, int port, string clientName)
    {
        FFClient.GetReady();
        FFSystem.GetReady();
        FFMessageSystem.GetReady();

        if ((singleton._clientData.IsOrBeingConnected = true &&
                                                        singleton._clientData.clientSocketTCP != null && singleton._clientData.clientSocketTCP.socket != null && singleton._clientData.clientSocketTCP.socket.IsBound) &&
            singleton._clientData.clientSocketUDP != null && singleton._clientData.clientSocketUDP.udpClient != null)
        {
            return;
        }

        singleton._clientData.IsOrBeingConnected = true;
        singleton._clientData.clientName         = clientName;
        singleton._ipAddress = ipAddress;
        singleton._port      = port;

        singleton._ipEndPoint = new IPEndPoint(IPAddress.Parse(singleton._ipAddress), singleton._port);

        try
        {
            // TCP
            singleton._clientData.clientSocketTCP = new ClientSocket(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp));
            singleton._clientData.clientSocketTCP.socket.BeginConnect(singleton._ipEndPoint, new AsyncCallback(ConnectCallback), singleton._clientData);
            singleton._clientData.clientSocketTCP.clientData = singleton._clientData;

            Debug.Log("Connecting to Server..." +
                      "\nIPEndPoint: " + singleton._ipEndPoint);
        }
        catch (Exception e)
        {
            Debug.Log("Client Failed to beging connecting to Server" +
                      "\nException: " + e.Message);
        }
    }
Exemple #8
0
    void Start()
    {
        // Events
        FFMessage <ChangeLevelStateEvent> .Connect(OnChangeLevelStateEvent);

        FFMessage <GetIPAddressEvent> .Connect(OnGetIPAddressEvent);

        // Sequence
        DisconnectSequence = action.Sequence();

        // MenuUI
        if (InputField_PlayerName == null ||
            InputField_ServerIPAddress == null ||
            InputButton_StartNewServer == null ||
            InputButton_JoinServer == null ||
            TextField_IPAddresses == null ||
            TextField_Notice == null)
        {
            Debug.LogError("Error, ExLevelController is missing a refernce to a MenuUI object");
            return;
        }

        // GameUI
        if (InputButton_LeaveServer == null ||
            TextField_Wave == null ||
            TextField_PlayerNames == null)
        {
            Debug.LogError("Error, ExLevelController is missing a refernce to a GameUI object");
            return;
        }

        // Setup Text Input Events from UI
        // MenuUI
        _inputField_playerName      = InputField_PlayerName.GetComponent <InputField>();
        _inputField_serverIPAddress = InputField_ServerIPAddress.GetComponent <InputField>();
        _inputButton_startNewServer = InputButton_StartNewServer.GetComponent <Button>();
        _inputButton_joinServer     = InputButton_JoinServer.GetComponent <Button>();
        _inputButton_quitGame       = InputButton_QuitGame.GetComponent <Button>();
        _textField_iPAddresses      = TextField_IPAddresses.GetComponent <Text>();
        _textField_notice           = TextField_Notice.GetComponent <Text>();

        // GameUI
        _inputButton_leaveServer = InputButton_LeaveServer.GetComponent <Button>();
        _textField_wave          = TextField_Wave.GetComponent <Text>();
        _textField_playerNames   = TextField_PlayerNames.GetComponent <Text>();

        // ------------------- Connect to events -------------------------------

        // MenuUI
        _inputField_playerName.onEndEdit.AddListener(OnSubmitPlayerName);
        _inputField_serverIPAddress.onEndEdit.AddListener(OnSubmitServerIPAddress);
        _inputButton_startNewServer.onClick.AddListener(OnClickStartNewServer);
        _inputButton_joinServer.onClick.AddListener(OnClickJoinServer);
        _inputButton_quitGame.onClick.AddListener(OnClickQuitGame);

        // GameUI
        _inputButton_leaveServer.onClick.AddListener(OnClickLeaveServer);

        // Set Text fields

        FFClient.GetLocalIPEventStart();
        FFClient.GetPublicIPEventStart();

        // Set Level State
        ChangeLevelStateEvent CLSE;

        CLSE.newState = LevelState.In_Menu;
        FFMessage <ChangeLevelStateEvent> .SendToLocal(CLSE);
    }
    void OnDestroy()
    {
        Debug.Log("FFClient Destroyed");
        _singleton = null;
        EndSendThread();

        try
        {
            if (_clientData.clientSocketTCP != null && _clientData.clientSocketTCP.socket != null && _clientData.clientSocketTCP.socket.IsBound)
            {
                _clientData.clientSocketTCP.socket.BeginDisconnect(false, new AsyncCallback(DisconnectCallback), _clientData.clientSocketTCP.socket);
                _clientData.clientSocketTCP.socket = null;
                _clientData.clientSocketTCP.clientData = null;
                _clientData.clientSocketTCP = null;
            }
        }
        catch (Exception exp) { Debug.Log("Error in FFServer OnDestroy() : " + exp.Message); }

        try
        {
            if (_clientData.clientSocketUDP != null && _clientData.clientSocketUDP.udpClient != null)
            {
                _clientData.clientSocketUDP.udpClient.Close();
                _clientData.clientSocketUDP.udpClient = null;
                _clientData.clientSocketUDP.udpEndPointLocal = null;
                _clientData.clientSocketUDP.udpEndPointRemote = null;
                _clientData.clientSocketUDP.socket = null;
                _clientData.clientSocketUDP.clientData = null;
                _clientData.clientSocketUDP = null;

            }
        }
        catch (Exception exp) { Debug.Log("Error in FFServer OnDestroy() : " + exp.Message); }

        FFLocalEvents.TimeChangeEvent TCE;
        TCE.newCurrentTime = FFSystem.time;
        FFMessage<FFLocalEvents.TimeChangeEvent>.SendToLocal(TCE);

        FFMessage<ClientConnectedEvent>.Disconnect(OnClientConnected);
        FFMessage<ClientSyncTimeEvent>.Disconnect(OnClientSyncTime);
    }
 public static void GetReady()
 {
     if(singleton == null)
     {
         GameObject newFFClient;
         newFFClient = new GameObject("FFClient");
         _singleton = newFFClient.AddComponent<FFClient>();
         FFMessage<ClientConnectedEvent>.Connect(OnClientConnected);
         FFMessage<ClientSyncTimeEvent>.Connect(OnClientSyncTime);
     }
 }
 private FFClient()
 {
     if (singleton != null)
     {
         Debug.LogError("Error created a second Singleton of FFNetServer");
         return;
     }
     _singleton = this;
 }
 public void Destroy()
 {
     _theThread.Abort();
     if (_ffc != null)
     {
         _ffc.Close();
         _ffc = null;
     }
 }
    void FFCManagerThreadFunc()
    {
        while (true)
        {
            if (_ffc == null)
            {
                _ffc = new FFClient();
                _ffc.OnAccountResponse += new EventHandler(_ffc_OnAccountResponse);
                _ffc.OnCourseCompletionInfo += _ffc_OnCourseCompletionInfo;
                _ffc.OnInventoryItem += _ffc_OnInventoryItem;

                _ffc.Connect(_address, _port);
            }

            if (_ffc != null && _ffc.Connected)
                _ffc.Update();

            Thread.Sleep(100);
        }
    }