Esempio n. 1
0
 public InvitationArrivedEventArgs(NtcInvite data)
 {
     sourcePlayerName = Encoding.UTF8.GetString(data.inviterName);
     joinCode         = Encoding.UTF8.GetString(data.enterCode);
     rule             = data.rule;
     url = Encoding.UTF8.GetString(data.inviterUrl);
 }
Esempio n. 2
0
        public void createGame(int roundCount, gameRule rule, Action <CreateOrJoinGameErrorCode, Action> completion)
        {
            var connection = ConnectionManager.sharedInstance.connectionNamed(Config.CONNECTION_NAME_MATCHMAKER);

            if (connection == null)
            {
                completion(CreateOrJoinGameErrorCode.CannotConnectToServer, () => {
                });
            }
            else
            {
                rule.PanType = 2;
                var data = new reqCreateGame();
                data.gameCfgId   = (int)_gameConfigId;
                data.rule        = rule;
                data.userName    = Encoding.Default.GetBytes(Account.localPlayer.userId);
                data.chargeCfgId = (from config in _chargConfigs
                                    where config.roundCount == roundCount
                                    select(int) config.chargeCfgId).FirstOrDefault();

                if (GameConfig.global.lastGameRoomId != -1)
                {
                    data.preRoomId = GameConfig.global.lastGameRoomId;
                    GameConfig.global.lastGameRoomId = -1;
                }

                var request = new Request <OurgameHeader> ((int)MatchMakerMessageID.CreateGame);
                request.setData(data);
                request.responseMessageId = (uint)MessageCategory.Ack | (uint)MatchMakerMessageID.CreateGame;
                request.responseCallback  = (response, responseCompletion) => {
                    var ack = response.read <ackCreateGame> ();
                    if (ack.result == 0)
                    {
                        GameConfig.global.enterCode = Encoding.Default.GetString(ack.enterCode);
                        responseCompletion();

                        joinGame(GameConfig.global.enterCode, completion);
                    }
                    else
                    {
                        completion((CreateOrJoinGameErrorCode)ack.result, responseCompletion);
                    }
                };

                connection.sendRequest(request);
            }
        }