Exemplo n.º 1
0
 IEnumerator PeriodicallyCheckCircle()
 {
     while (true)
     {
         Helper.ServerRequest getCirc = new Helper.ServerRequest()
         {
             request = Helper.ServerRequestType.RecieveCircle
         };
         StartCoroutine(SendRequest <Vector2, Helper.CircleOfAction>(getCirc, new Vector3(GameController.Instance.CurrentGpsPosition.Latitude, GameController.Instance.CurrentGpsPosition.Longitude), true, (returnValue) => {
             GameController.Instance.circle = returnValue;
         }));
         yield return(new WaitForSeconds(60));
     }
 }
Exemplo n.º 2
0
    IEnumerator PeriodicallyGetPlayerPositions()
    {
        while (true)
        {
            yield return(new WaitForSeconds(10));

            Helper.ServerRequest getPos = new Helper.ServerRequest()
            {
                request = Helper.ServerRequestType.RecievePositions
            };
            StartCoroutine(SendRequest <Vector2, Helper.PlayerLocationWrapper>(getPos, new Vector2(GameController.Instance.CurrentGpsPosition.Latitude, GameController.Instance.CurrentGpsPosition.Longitude), true, (returnValue) => {
                GC.playerPositions = returnValue.list;
                GameObject.FindGameObjectWithTag("Map").GetComponent <MapObjects>().positionPlayers(returnValue.list);
            }));
        }
    }
Exemplo n.º 3
0
    IEnumerator PeriodicallySendPosition()
    {
        while (true)
        {
            yield return(new WaitForSeconds(10));

            Helper.ServerRequest sendPos = new Helper.ServerRequest()
            {
                request = Helper.ServerRequestType.SendPosition
            };
            StartCoroutine(SendRequest <Helper.PlayerLocation, string>(sendPos, new Helper.PlayerLocation()
            {
                position = new Vector2(GameController.Instance.CurrentGpsPosition.Latitude, GameController.Instance.CurrentGpsPosition.Longitude), id = GameController.Instance.player.id, name = GameController.Instance.player.name, timestamp = DateTime.UtcNow.ToString()
            }));
        }
    }
Exemplo n.º 4
0
 public void tryToRegister(string name, string password)
 {
     Helper.ServerRequest tryRegister = new Helper.ServerRequest()
     {
         request = Helper.ServerRequestType.NewPlayer
     };
     Helper.LoginCredentials login = new Helper.LoginCredentials()
     {
         name = name, password = password
     };
     StartCoroutine(SendRequest <Helper.LoginCredentials, Helper.Player>(tryRegister, login, true, (returnValue) => {
         if (OnLoginResult != null)
         {
             OnRegisterResult(returnValue);
         }
     }));
 }
Exemplo n.º 5
0
    public void tryToLogin(string name, string password)
    {
        //subscribe to the OnLoginResult event to get the result of this function

        Helper.ServerRequest tryLogin = new Helper.ServerRequest()
        {
            request = Helper.ServerRequestType.LogIn
        };
        Helper.LoginCredentials login = new Helper.LoginCredentials()
        {
            name = name, password = password
        };
        // System.Action<Helper.Player> ac = new System.Action<Helper.Player>(loginResult);
        StartCoroutine(SendRequest <Helper.LoginCredentials, Helper.Player>(tryLogin, login, true, (returnValue) => {
            if (OnLoginResult != null)
            {
                OnLoginResult(returnValue);
            }
        }));
    }
Exemplo n.º 6
0
    public IEnumerator SendRequest <TRequest, TAnswer>(Helper.ServerRequest request, TRequest data, bool expectAnswer = false, System.Action <TAnswer> answer = null)
    {
        byte[]     toSend = new byte[1024];
        IPEndPoint ipep   = new IPEndPoint(IPAddress.Parse(Config.ServerIP), Config.ServerPort);
        Socket     server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

        toSend = Encoding.ASCII.GetBytes(JsonUtility.ToJson(request));
        if (data == null || String.IsNullOrEmpty(data.ToString()))
        {
            toSend = Encoding.ASCII.GetBytes(JsonUtility.ToJson(request));
        }
        else
        {
            toSend = Encoding.ASCII.GetBytes(JsonUtility.ToJson(request) + ";" + JsonUtility.ToJson(data));
        }

        server.SendTo(toSend, toSend.Length, SocketFlags.None, ipep);

        if (expectAnswer)
        {
            byte[]     toRecieve = new byte[1024];
            IPEndPoint sender    = new IPEndPoint(IPAddress.Any, 0);
            EndPoint   tmpRemote = (EndPoint)sender;

            int recv = server.ReceiveFrom(toRecieve, ref tmpRemote);
            // Debug.Log("Answer: " + Encoding.ASCII.GetString(toRecieve, 0, recv));
            if (answer != null)
            {
                if (Encoding.ASCII.GetString(toRecieve, 0, recv).Equals("null"))
                {
                    answer(default(TAnswer));
                }
                else
                {
                    answer(JsonUtility.FromJson <TAnswer>(Encoding.ASCII.GetString(toRecieve, 0, recv).Replace("\"X\"", "\"x\"").Replace("\"Y\"", "\"y\"")));
                }
            }
        }
        server.Close();
        yield return(null);
    }
Exemplo n.º 7
0
    IEnumerator timeoutToWin()
    {
        Helper.ServerRequest attack = new Helper.ServerRequest()
        {
            request = Helper.ServerRequestType.CreatePoint
        };
        Helper.NewPointAttack pa = new Helper.NewPointAttack()
        {
            attack = Helper.Attacks.Rain, playerID = GameController.Instance.player.id, circleID = Config.attackedPoint.circleID, pointID = Config.attackedPoint.id
        };
        Debug.Log(pa.circleID + " " + pa.pointID + " " + pa.attack);
        StartCoroutine(UDPClient.Instance.SendRequest <Helper.NewPointAttack, Helper.CircleOfAction>(attack, pa));
        Config.minigameSuccess = true;
        Helper.ServerRequest getCirc = new Helper.ServerRequest()
        {
            request = Helper.ServerRequestType.RecieveCircle
        };
        StartCoroutine(UDPClient.Instance.SendRequest <Vector2, Helper.CircleOfAction>(getCirc, new Vector3(GameController.Instance.CurrentGpsPosition.Latitude, GameController.Instance.CurrentGpsPosition.Longitude), true, (returnValue) => {
            GameController.Instance.circle = returnValue;
        }));
        yield return(new WaitForSeconds(5));

        SceneManager.LoadScene("MainGame");
    }