예제 #1
0
        /// <summary>
        /// Create Your Player in your Game
        /// </summary>
        ///  <param name="PlayerSchema"> the Schema of player you want to create </param>
        /// <return></return>
        public async static Task <ApiResponse> CreatePlayer <T>(T PlayerSchema)
        {
            string stringJSON = JsonConvert.SerializeObject(PlayerSchema);
            var    body       = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(stringJSON);

            if (body.ContainsKey("password") == true)
            {
                body["password"] = GCPolicy.Md5Generator(body["password"]);
            }
            else
            {
                return(new ApiResponse(false, -751));
            }
            ServerResponse req = await PostRequestAsync("/players/v2/register", body);

            var resp = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(req.responseMessage);

            if (req.IsSuccess)
            {
                _playerToken = resp["token"];
                resp.Remove("token");
                return(new ApiResponse(true, req.responseStatusCode, resp));
            }
            else if (resp["ecode"] == 10012)
            {
                return(new ApiResponse(false, 10012, null));
            }

            return(new ApiResponse(false, req.responseStatusCode, null));
        }
예제 #2
0
        /// <summary>
        /// change player password
        /// </summary>
        ///  <param name="tmpCode"> the code that recieved by email or phone number</param>
        ///  <param name="newPassword"> the new password that want to be changed</param>
        /// <return></return>
        public static async Task <ApiResponse> ChangePassword(string tmpCode, string newPassword)
        {
            Dictionary <string, dynamic> body = new Dictionary <string, dynamic>();

            if (tmpCode != null)
            {
                body.Add("tmpCode", tmpCode);
            }
            if (newPassword != null)
            {
                body.Add("newPassword", GCPolicy.Md5Generator(newPassword));
            }

            ServerResponse req = await PutRequestAsync("players/v2/forgot/changePassword", body);

            var resp = (JObject)JsonConvert.DeserializeObject(req.responseMessage);

            if (req.IsSuccess)
            {
                bool instance = resp["change"].ToObject <bool>();
                return(new ApiResponse(instance, req.responseStatusCode, null));
            }
            else
            {
                if (resp["ecode"].ToObject <int>() == 10074)
                {
                    return(new ApiResponse(false, 10074, null));
                }
            }
            return(new ApiResponse(false, req.responseStatusCode, null));
        }
예제 #3
0
        ///<summary>
        ///connect to server
        ///</summary>
        public void ConnectToMultiPlayerServer()
        {
            if (!internetConnection)
            {
                Debug.LogError("[GamingCloud] Internet Connection Not Reachable! Please Try Again Later");
                return;
            }

            if (isConnected)
            {
                Debug.LogWarning("[GamingCloud] You are Connected To Server");
                return;
            }


            if (gameObject.GetComponent <UnityMainThreadDispatcher>() == null)
            {
                gameObject.AddComponent(typeof(UnityMainThreadDispatcher));
            }

            streamer = new tcpStreamer(BASE_URL, PORT, packetSize);
            streamer.OnPacketRecieve += listenData;
            streamer.OnConnected     += () =>
            {
                UnityMainThreadDispatcher.Instance().Enqueue(() =>
                {
                    this._isConnected = true;
                    Dictionary <string, string> payload = GCPolicy.GetRequiredQueries(GCPolicy.QueryMode.TCP);

                    string pid;
                    if (this.testPlayerId.Length > 0)
                    {
                        pid = this.testPlayerId;
                    }
                    else if (!Players.IsLogin)
                    {
                        Debug.LogError("[GamingCloud] You are supposed to login to gamingcloud player account!");
                        return;
                    }
                    else
                    {
                        pid = Players.PlayerToken;
                    }

                    if (pid == null || pid.Trim().Length == 0)
                    {
                        Debug.LogError("[GamingCloud] You are supposed to login to gamingcloud player account!");
                        return;
                    }
                    payload.Add("PlayerId", pid);
                    this.sendPacket("authentication", this._netId, JsonConvert.SerializeObject(payload));
                });
            };
        }
예제 #4
0
        // static string baseURL = "http://localhost:4000";
        // static string baseURL = "http://172.16.73.123:4000";
        static void SetHeader(HttpClient client)
        {
            foreach (KeyValuePair <string, string> item in GCPolicy.GetRequiredQueries(GCPolicy.QueryMode.HTTP))
            {
                client.DefaultRequestHeaders.Add(item.Key, item.Value);
            }



            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        }
예제 #5
0
        /// <summary>
        /// login your player in game
        /// </summary>
        ///  <param name="playerName"> the username of your player </param>
        ///  <param name="password"> the password of your player </param>
        /// <return></return>
        public static async Task <ApiResponse> Login(string playerName, string password)
        {
            string pass = "";

            if (password == "guest")
            {
                pass = "******";
            }
            else
            {
                pass = GCPolicy.Md5Generator(password);
            }
            ServerResponse req = await GetRequestAsync("/players/v2/login/" + playerName + "/" + pass);

            var resp = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(req.responseMessage);

            if (req.IsSuccess)
            {
                _playerToken = resp["token"];
                resp.Remove("token");
                return(new ApiResponse(true, 200, resp));
            }
            else if (resp["ecode"] == 404)
            {
                return(new ApiResponse(false, 404, null));
            }
            else if (resp["ecode"] == 10090)
            {
                return(new ApiResponse(false, 10090, null));
            }
            else if (resp["ecode"] == 10091)
            {
                return(new ApiResponse(false, 10091, null));
            }
            return(new ApiResponse(false, req.responseStatusCode, null));
        }