Ejemplo n.º 1
0
        public Friend(HicoreSocket socket)
        {
            this._socket = socket;


            _socket.On(searchFriendEvent, res =>
            {
                OnSearchFriendResult(new Result(res.Text));
            });

            _socket.On(requestFriendEvent, res =>
            {
                OnRequestFriendResult(new Result(res.Text));
            });

            _socket.On(acceptFriendEvent, res =>
            {
                OnAcceptFriendResult(new Result(res.Text));
            });

            _socket.On(rejectFriendEvent, res =>
            {
                OnRejectFriendResult(new Result(res.Text));
            });

            _socket.On(removeFriendEvent, res =>
            {
                OnRemoveFriendResult(new Result(res.Text));
            });
        }
Ejemplo n.º 2
0
        public DataStorage(HicoreSocket socket)
        {
            this._socket = socket;


            _socket.On(createClassEvent, res =>
            {
                OnCrateClassResult(new Result(res.Text));
            });

            _socket.On(updateClassEvent, res =>
            {
                OnUpdateClassResult(new Result(res.Text));
            });

            _socket.On(incrementValueEvent, res =>
            {
                OnIncrementValueResult(new Result(res.Text));
            });

            _socket.On(catchDataEvent, res =>
            {
                OnFetchDataResult(new Result(res.Text));
            });

            _socket.On(deleteObjectEvent, res =>
            {
                OnDeleteObjectResult(new Result(res.Text));
            });
        }
Ejemplo n.º 3
0
        public Communication(HicoreSocket socket)
        {
            this._socket = socket;



            _socket.On(messageToIdEvent, res =>
            {
                OnMessageToIdResult(new Result(res.Text));
            });

            _socket.On(messageToGroupEvent, res =>
            {
                OnMessageToGroupResult(new Result(res.Text));
            });


            _socket.On(receiveMessageListener, res =>
            {
                JSONNode jsonRes = JSON.Parse(res.Text);

                Message msg = new Message();

                msg.Type           = jsonRes["type"].Value;
                msg.Text           = jsonRes["text"].Value;
                msg.SenderId       = jsonRes["senderId"].Value;
                msg.SenderUsername = jsonRes["senderUsername"].Value;
                msg.SenderSocketId = jsonRes["senderSocketId"].Value;

                OnMessage(msg);
            });
        }
Ejemplo n.º 4
0
        public StaticDataStorage(HicoreSocket socket)
        {
            this._socket = socket;

            _socket.On(fetchStaticDataEvent, res =>
            {
                OnFetchStaticDataResult(new Result(res.Text));
            });
        }
Ejemplo n.º 5
0
        public UpdateAccount(HicoreSocket socket)
        {
            this._socket = socket;


            curTimeZone   = TimeZone.CurrentTimeZone;
            currentOffset = curTimeZone.GetUtcOffset(DateTime.Now);

            _socket.On(updateUserProfileEvent, res =>
            {
                OnUpdateProfileResult(new Result(res.Text));
            });

            _socket.On(updateUserUsernameEvent, res =>
            {
                JSONNode jsonRes = JSON.Parse(res.Text);

                Result result = new Result();

                result.Type    = jsonRes["type"].Value;
                result.Message = jsonRes["msg"].Value;
                result.Code    = jsonRes["code"].AsInt;

                if (jsonRes["data"] != null)
                {
                    //  renew Token
                    Client.Token = jsonRes["data"]["token"].Value;
                }

                OnUpdateUsernameResult(result);
            });

            _socket.On(updateUserEmailEvent, res =>
            {
                OnUpdateEmailResult(new Result(res.Text));
            });

            _socket.On(updateUserPasswordEvent, res =>
            {
                OnUpdatePasswordResult(new Result(res.Text));
            });

            _socket.On(updateGameInfoEvent, res =>
            {
                OnUpdateGameInfoResult(new Result(res.Text));
            });

            _socket.On(updateUserXpProgressEvent, res =>
            {
                OnUpdateUserXpProgressResult(new Result(res.Text));
            });

            _socket.On(updateUserSkillProgressEvent, res =>
            {
                OnUpdateUserSkillProgressResult(new Result(res.Text));
            });
        }
Ejemplo n.º 6
0
        public MatchController(HicoreSocket socket)
        {
            this._socket = socket;


            _socket.On(isMatchInProgressEvent, res => { OnIsMatchInProgressResult(new Result(res.Text)); });

            _socket.On(joinToMatchEvent, res => { OnJoinToMatchResult(new Result(res.Text)); });

            _socket.On(leaveMatchEvent, res => { OnLeaveMatch(new Result(res.Text)); });

            _socket.On(endOfMatchEvent, res =>
            {
                JSONNode jsonRes   = JSON.Parse(res.Text);
                FinalResult result = new FinalResult();

                result.Message = jsonRes["msg"].Value;
                result.Data    = jsonRes["data"];

                OnEnd(result);
            });
        }
Ejemplo n.º 7
0
        public Matchmacker(HicoreSocket socket)
        {
            this._socket = socket;

            _socket.On(requestMatchEvent, res => { OnRequestMatchResult(new Result(res.Text)); });

            _socket.On(cancelMatchEvent, res => { OnCancelMatchResult(new Result(res.Text)); });

            _socket.On(createPlaymateMatchEvent, res => { OnCreatePlaymateMatchResult(new Result(res.Text)); });

            _socket.On(destroyPlaymateMatchEvent, res => { OnDestroyPlaymateMatchResult(new Result(res.Text)); });

            _socket.On(invitePlaymateEvent, res => { OnInvitePlaymateResult(new Result(res.Text)); });

            _socket.On(acceptPlaymateEvent, res => { OnAcceptPlaymateResult(new Result(res.Text)); });
            _socket.On(denyPlaymateEvent, res => { OnDenyPlaymateResult(new Result(res.Text)); });

            _socket.On(leavePlaymateEvent, res => { OnLeavePlaymateResult(new Result(res.Text)); });


            // Listener events
            _socket.On(matchmakingResultListenerEvent, res =>
            {
                JSONNode jsonRes = JSON.Parse(res.Text);


                List <MatchmakerResult> opponents = new List <MatchmakerResult>();
                foreach (JSONNode r in jsonRes)
                {
                    MatchmakerResult result = new MatchmakerResult();
                    result.MatchId          = r["matchId"].Value;
                    result.PlaymateUserId   = r["userId"].Value;
                    result.PlaymateUsername = r["username"].Value;
                    result.PlaymateId       = r["playmateId"].Value;
                    result.PlaymateSocketId = r["socketId"].Value;
                    result.PlaymateLevel    = r["level"].AsInt;
                    result.PlaymateRank     = r["rank"].AsInt;
                    result.Team             = r["team"].AsInt;

                    opponents.Add(result);
                }

                OnMatchmaking(opponents);
            });


            _socket.On(playmateResultListenerEvent, res =>
            {
                JSONNode jsonRes = JSON.Parse(res.Text);

                PlaymateResult result = new PlaymateResult();

                result.Type = jsonRes["type"].Value;
                result.Code = jsonRes["code"].AsInt;

                if (jsonRes["code"].AsInt == 0) // invite result
                {
                    result.UserId       = jsonRes["userId"].Value;
                    result.Username     = jsonRes["username"].Value;
                    result.UserSocketId = jsonRes["userSocketId"].Value;
                    result.PlaymateId   = jsonRes["playmateId"].Value;
                }

                if (jsonRes["code"].AsInt == 1) // accept result
                {
                    result.UserId   = jsonRes["userId"].Value;
                    result.Username = jsonRes["username"].Value;
                }

                if (jsonRes["code"].AsInt == 2) // deny result
                {
                    result.UserId   = jsonRes["userId"].Value;
                    result.Username = jsonRes["username"].Value;
                }

                if (jsonRes["code"].AsInt == 3) // leave
                {
                    result.UserId   = jsonRes["userId"].Value;
                    result.Username = jsonRes["username"].Value;
                }

                if (jsonRes["code"].AsInt == 4) // queue
                {
                    result.Message = jsonRes["msg"].Value;
                }

                if (jsonRes["code"].AsInt == 5) // cancel search for game
                {
                    result.Message = jsonRes["msg"].Value;
                }

                if (jsonRes["code"].AsInt == 6) // destroy
                {
                    result.Message = jsonRes["msg"].Value;
                }


                OnPlaymate(result);
            });
        }
Ejemplo n.º 8
0
        public Client(HicoreSocket socket)
        {
            if (_socket == null)
            {
                this._socket = socket;
                Token        = "";

                result = new Result();
                user   = new User();

                curTimeZone   = TimeZone.CurrentTimeZone;
                currentOffset = curTimeZone.GetUtcOffset(DateTime.Now);


                MatchController = new MatchController(_socket);
                UpdateAccount   = new UpdateAccount(_socket);
                Friend          = new Friend(_socket);
                Matchmacker     = new Matchmacker(_socket);
                Communication   = new Communication(_socket);
                Storage         = new DataStorage(_socket);
                StaticStorage   = new StaticDataStorage(_socket);

                _socket.On(authenticateDeviceIdEvent, res =>
                {
                    JSONNode jsonRes = JSON.Parse(res.Text);

                    if (jsonRes["type"].Value.Equals(result.Success))
                    {
                        user.UserId             = jsonRes["userId"].Value;
                        user.Username           = jsonRes["username"].Value;
                        user.Token              = jsonRes["token"].Value;
                        user.GameInfo           = jsonRes["gameInfo"];
                        user.FriendRequest      = jsonRes["friendRequest"];
                        user.FriendList         = jsonRes["friendList"];
                        user.TotalFriendRequest = jsonRes["totalFriendRequest"];


                        result.Type    = jsonRes["type"].Value;
                        result.Message = jsonRes["msg"].Value;
                        result.Code    = jsonRes["code"].AsInt;


                        // save token to update account
                        Token = jsonRes["token"].Value;

                        // send user token to Game Server
                        ChildServer?.SendToken();

                        OnAuthenticateDeviceId(user, result);
                    }
                    else
                    {
                        result.Type    = jsonRes["type"].Value;
                        result.Message = jsonRes["msg"].Value;
                        result.Code    = jsonRes["code"].AsInt;
                        OnAuthenticateDeviceId(user, result);
                    }
                });

                _socket.On(authenticateEmailEvent, res =>
                {
                    JSONNode jsonRes = JSON.Parse(res.Text);

                    if (jsonRes["type"].Value.Equals(result.Success))
                    {
                        user.UserId             = jsonRes["userId"].Value;
                        user.Username           = jsonRes["username"].Value;
                        user.Token              = jsonRes["token"].Value;
                        user.GameInfo           = jsonRes["gameInfo"];
                        user.FriendRequest      = jsonRes["friendRequest"];
                        user.FriendList         = jsonRes["friendList"];
                        user.TotalFriendRequest = jsonRes["totalFriendRequest"];

                        result.Type    = jsonRes["type"].Value;
                        result.Message = jsonRes["msg"].Value;
                        result.Code    = jsonRes["code"].AsInt;


                        // save token to update account
                        Token = jsonRes["token"].Value;
                        // send user token to Game Server
                        ChildServer?.SendToken();


                        OnAuthenticateEmail(user, result);
                    }
                    else
                    {
                        result.Type    = jsonRes["type"].Value;
                        result.Message = jsonRes["msg"].Value;
                        result.Code    = jsonRes["code"].AsInt;
                        OnAuthenticateEmail(user, result);
                    }
                });
            }
            else
            {
                throw new ArgumentException("Socket is already in use");
            }
        }