Exemplo n.º 1
0
    private void ConnectToGameServer()
    {
        if (caseomaticUsername == "")
        {
            Debug.Log("You cannot connect to the game server without a specified username.");
            return;
        }
        if (gameDataServerConnectionMode == GameDataServerConnectionMode.Connected)
        {
            Debug.Log("You cannot connect to the game server if you already are connected.");
            return;
        }

        try
        {
            isLoading = true;
            gameDataServerEndPoint = new IPEndPoint(IPAddress.Loopback, 42001); // Find out the game server endpoint

            socket = new ClientSocket(gameDataServerClientPort);
            socket.Connect(gameDataServerEndPoint);
            progress += 25;

            SendGameServerMessage("login", caseomaticUsername, projectBronzeAgeUserId);
            progress += 25;
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
            gameDataServerConnectionMode = GameDataServerConnectionMode.Aborted;
            loadErrorOccured             = true;
        }
    }
Exemplo n.º 2
0
 private void SendGameServerMessage(string type, params string[] args)
 {
     try
     {
         socket.Send(new SocketMessage(type, args));
     }
     catch (Exception ex)
     {
         Debug.LogException(ex);
         gameDataServerConnectionMode = GameDataServerConnectionMode.Aborted;
     }
 }
Exemplo n.º 3
0
    private void ReceiveUserData()
    {
        try
        {
            gameDataServerConnectionMode = GameDataServerConnectionMode.Initializing;
            caseomaticUsername           = Environment.GetCommandLineArgs()[1];

            progress += 25;
        }
        catch (Exception)
        {
            Debug.LogError("The application got started without commandline arguments. Aborting...");
            gameDataServerConnectionMode = GameDataServerConnectionMode.Aborted;

            loadErrorOccured = true;
        }
    }
Exemplo n.º 4
0
    private void ReceiveGameServerMessages()
    {
        try
        {
            gameDataServerConnectionMode = GameDataServerConnectionMode.Connected;
            while (gameDataServerConnectionMode != GameDataServerConnectionMode.Aborted)
            {
                var msg = socket.Receive();

                switch (msg.type)
                {
                case "register":
                    break;

                case "login":
                    if (msg.data[0] == "success")
                    {
                        userInfo = GameDataUserInfo.FromBytes(ASCIIEncoding.ASCII.GetBytes(msg.data[1]));
                        projectBronzeAgeUserId = msg.data[2];

                        progress += 25;
                        isDone    = true;
                        isLoading = false;
                    }
                    else
                    {
                        Debug.LogError("Your username does not exist, creating account...");
                        SendGameServerMessage("register", caseomaticUsername);
                    }
                    break;

                case "logout":
                    gameDataServerConnectionMode = GameDataServerConnectionMode.ShutDown;
                    break;

                case "dchange":
                    break;
                }
            }
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
            gameDataServerConnectionMode = GameDataServerConnectionMode.Aborted;
        }
    }
Exemplo n.º 5
0
    private void CloseGameServerConnection()
    {
        try
        {
            if (gameDataServerConnectionMode == GameDataServerConnectionMode.Connected)
            {
                SendGameServerMessage("logout", projectBronzeAgeUserId);

                socket.Stop();
                socket = null;
            }
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
            gameDataServerConnectionMode = GameDataServerConnectionMode.Aborted;
        }
    }