Exemplo n.º 1
0
 // Start is called before the first frame update
 void Start()
 {
     if (GameObject.Find("NetworkManager"))
     {
         netManager = GameObject.Find("NetworkManager").GetComponent <FPSNetworkCode.NetworkManager>();
         netManager.ConnectToServer();
     }
 }
Exemplo n.º 2
0
        public bool CommandReader(string getMsg)
        {
            string usernameHolder     = "";
            string passwordHolder     = ""; //temp plain text
            int    passwordStartIndex = -1;

            if (getMsg[0] != '/')   //Only process commands with '/' prefix
            {
                return(false);
            }

            if (!netManagerRef)
            {
                Debug.LogError("[Error] Network Manager reference missing! Aborting operation... ");
                if (bDebugToConsole)
                {
                    UpdateChat("[Error] Network Manager reference missing! Aborting operation... ");
                }
                return(false);
            }

            if (getMsg == "/connect")
            {
                UpdateChat("[Console] Connecting to server... ");
                netManagerRef.ConnectToServer();
                return(true);
            }

            if (getMsg.Length > 7)
            {
                if (getMsg.Substring(1, 6).ToLower() == "login ")
                {
                    //Get username from syntax. its the first word after '/login '
                    for (int i = 7; i < getMsg.Length; i++)
                    {
                        if (getMsg[i] == ' ')
                        {
                            passwordStartIndex = i + 1;
                            break;
                        }
                        usernameHolder = usernameHolder + getMsg[i];
                    }

                    if (passwordStartIndex == -1 || passwordStartIndex > getMsg.Length)
                    {
                        UpdateChat("[Console] Invalid syntax.");
                        return(false);
                    }

                    //Get password from syntax. its the word after the username
                    for (int i = passwordStartIndex; i < getMsg.Length; i++)
                    {
                        passwordHolder = passwordHolder + getMsg[i];
                    }

                    netManagerRef.AttemptLogin(usernameHolder, passwordHolder);
                    return(true);
                }
            }

            if (getMsg.Length > 9)
            {
                if (getMsg.Substring(1, 9).ToLower() == "register ")
                {
                    //Get username from syntax. its the first word after '/login '
                    for (int i = 10; i < getMsg.Length; i++)
                    {
                        if (getMsg[i] == ' ')
                        {
                            passwordStartIndex = i + 1;
                            break;
                        }
                        usernameHolder = usernameHolder + getMsg[i];
                    }

                    if (passwordStartIndex == -1 || passwordStartIndex >= getMsg.Length)
                    {
                        UpdateChat("[Console] Invalid syntax.");
                        return(false);
                    }

                    //Get password from syntax. its the word after the username
                    for (int i = passwordStartIndex; i < getMsg.Length; i++)
                    {
                        passwordHolder = passwordHolder + getMsg[i];
                    }

                    netManagerRef.AttemptAccountCreation(usernameHolder, passwordHolder);
                    return(true);
                }
            }

            if (getMsg.Length > 7)
            {
                if (getMsg.Substring(1, 6).ToLower() == "fetch ")
                {
                    if (getMsg.Substring(7, 14).ToLower() == "profile ")
                    {
                        for (int i = 15; i < getMsg.Length; i++)
                        {
                            if (getMsg[i] == ' ')
                            {
                                passwordStartIndex = i + 1;
                                break;
                            }
                            usernameHolder = usernameHolder + getMsg[i];
                        }
                        netManagerRef.RequestProfileData(usernameHolder);
                    }
                    else if (getMsg.Substring(7, 14).ToLower() == "clientdata ")
                    {
                        //TODO
                    }
                    return(true);
                }
            }

            if (getMsg == "/join any" || getMsg == "/join matchmaking" || getMsg == "/join")
            {
                UpdateChat("[Console] Joining matchmaking... ");
                netManagerRef.QueueMatchMaking();
                return(true);
            }

            if (getMsg == "/leave" || getMsg == "/leave lobby")
            {
                netManagerRef.LeaveMatchMakingQueue();
                return(true);
            }

            if (getMsg == "/disconnect")
            {
                netManagerRef.Disconnect();
                return(true);
            }

            Debug.Log("[Notice] Invalid Command. ");
            UpdateChat("[Console] Invalid Command. ");
            return(false);
        }