protected void CheckUnsolicitedUdp(List <byte> header, GameServerInfo serverInfo)
 {
     if (serverInfo.ServerData.ContainsKey("allow_unsolicited_udp"))
     {
         var unsolicitedUdp = int.Parse(serverInfo.ServerData["unsolicitedudp"]);
         if (unsolicitedUdp == 1)
         {
             header[0] ^= (byte)GameServerFlags.UnsolicitedUdpFlag;
         }
     }
 }
예제 #2
0
 /// <summary>
 /// Event handler for when a user selects a server
 /// </summary>
 /// <param name="obj">The highlighted Field in the Listview. Used</param>
 /// <param name="e">Not used</param>
 void SelectionChanged(object sender, TomShane.Neoforce.Controls.EventArgs e)
 {
     form.Play.Enabled = true;
     string[] serverInfo = form.Items[form.SelectedIndex];
     foreach (GameServerInfo server in serverList)
     {
         if (server.Name == serverInfo[0])
         {
             selectedServer = server;
         }
     }
 }
 protected void CheckNatNegFlag(List <byte> header, GameServerInfo serverInfo)
 {
     if (serverInfo.ServerData.ContainsKey("natneg"))
     {
         var natNegFlag     = int.Parse(serverInfo.ServerData["natneg"]);
         var unsolicitedUdp = header[0] & (byte)GameServerFlags.UnsolicitedUdpFlag;
         if (natNegFlag == 1 && unsolicitedUdp == 0)
         {
             header[0] ^= (byte)GameServerFlags.ConnectNegotiateFlag;
         }
     }
 }
 protected void CheckNonStandardPort(List <byte> header, GameServerInfo serverInfo)
 {
     // !! only dedicated server have different query report port and host port
     // !! but peer server have same query report port and host port
     // todo we have to check when we need send host port or query report port
     if (serverInfo.QueryReportPort != ClientInfo.QueryReportDefaultPort)
     {
         header[0] ^= (byte)GameServerFlags.NonStandardPort;
         byte[] htonPort = BitConverter.GetBytes((ushort)serverInfo.QueryReportPort).Reverse().ToArray();
         header.AddRange(htonPort);
     }
 }
예제 #5
0
 public void GoServerMainGate(GameServerInfo server, long userID, string session)
 {
     GameServer  = server;
     UserID      = userID;
     SesssionKey = session;
     GoToMainGate(server);
     PlayerPrefs.SetString("_PlayerSession", session);
     PlayerPrefs.SetString("_UserID", UserID.ToString());
     PlayerPrefs.SetInt("_GateServerPort", server.Port);
     PlayerPrefs.SetString("_GateServerHost", server.Host);
     PlayerPrefs.SetInt("_GateServerID", server.ServerID);
 }
예제 #6
0
        /// <inheritdoc />
        protected override void OnListenerStarted()
        {
            this.gameServerInfo = new GameServerInfo(
                this.config.ServerCode,
                this.GameServerEndPoint.ExternalHost ?? this.BoundEndPoint.Address.ToString(),
                this.GameServerEndPoint.ExternalPort ?? (ushort)this.BoundEndPoint.Port,
                (uint)this.clientController.ClientsConnected,
                (uint)this.config.MaxConnections);

            this.gameServerRegistrar.RegisterGameServerAsync(this.gameServerInfo)
            .ContinueWith(t => this.OnServerRegisterException(t.Exception), TaskContinuationOptions.OnlyOnFaulted);
            base.OnListenerStarted();
        }
 protected void CheckNonStandardPrivatePort(List <byte> header, GameServerInfo serverInfo)
 {
     // we check private port here
     if (serverInfo.ServerData.ContainsKey("localport"))
     {
         if (serverInfo.ServerData["localport"] != "" &&
             serverInfo.ServerData["localport"] != ClientInfo.QueryReportDefaultPort.ToString())
         {
             header[0] ^= (byte)GameServerFlags.NonStandardPrivatePortFlag;
             byte[] port = BitConverter.GetBytes(short.Parse(serverInfo.ServerData["localport"]));
             header.AddRange(port);
         }
     }
 }
        /// <summary>
        /// Start the loading screen state, which initializes some basic form components.
        /// </summary>
        /// <param name="gameServer">Server to connect to.</param>
        public LoadingScreenState(GameServerInfo gameServer)
        {
            server = gameServer;
            if (ServiceManager.Game.IsMouseVisible == false)
            {
                ServiceManager.Game.IsMouseVisible = true;
            }

            form = new LoadingScreen(ServiceManager.Game.Manager);
            ServiceManager.Game.FormManager.SwitchWindows(form.Window);
            form.Cancel.Click += new TomShane.Neoforce.Controls.EventHandler(Cancel_Click);

            State = LoadingState.LOADING;
            thread = new Thread(new ThreadStart(Start));
        }
예제 #9
0
        /// <summary>
        /// Start the loading screen state, which initializes some basic form components.
        /// </summary>
        /// <param name="gameServer">Server to connect to.</param>
        public LoadingScreenState(GameServerInfo gameServer)
        {
            server = gameServer;
            if (ServiceManager.Game.IsMouseVisible == false)
            {
                ServiceManager.Game.IsMouseVisible = true;
            }

            form = new LoadingScreen(ServiceManager.Game.Manager);
            ServiceManager.Game.FormManager.SwitchWindows(form.Window);
            form.Cancel.Click += new TomShane.Neoforce.Controls.EventHandler(Cancel_Click);

            State  = LoadingState.LOADING;
            thread = new Thread(new ThreadStart(Start));
        }
예제 #10
0
 public override Task <GameServerLoginResult> GameServerLogin(GameServerInfo request, ServerCallContext context)
 {
     if (GameServers.ContainsKey(request.ServerName))
     {
         Console.WriteLine("有个同名服务器链接!");
         return(Task.FromResult <GameServerLoginResult>(new GameServerLoginResult {
             IsSuccess = false
         }));
     }
     else
     {
         Console.WriteLine($"游戏服务器{request.ServerName}连接到服务器!");
         GameServers.TryAdd(request.ServerName, request);
     }
     return(base.GameServerLogin(request, context));
 }
        protected override void RequestCheck()
        {
            base.RequestCheck();
            if (_client.Info.AdHocMessage is null)
            {
                throw new SBException("There are no server messages in _session.ServerMessageList.");
            }

            _gameServer = _gameServerRedisClient.Context.FirstOrDefault(x =>
                                                                        x.HostIPAddress == _client.Info.AdHocMessage.TargetIPEndPoint.Address &
                                                                        x.QueryReportPort == (ushort)_client.Info.AdHocMessage.TargetIPEndPoint.Port);
            if (_gameServer is null)
            {
                throw new SBException("There is no matching game server regesterd.");
            }
        }
예제 #12
0
        protected void initItem(int index, GameServerInfo sinfo)
        {
            if (index >= content.childCount)
            {
                var prefab = content.GetChild(0);
                GameObject.Instantiate(prefab, content);
            }

            var infoT = content.GetChild(index);

            infoT.GetChild(0).GetComponent <Text>().text = sinfo.name;
            infoT.GetChild(1).GetComponent <Text>().text = $"{sinfo.curPlayerCount} / {sinfo.maxPlayerCount}";

            if (showPing)
            {
                StartCoroutine(pingE(sinfo.ip, infoT.GetChild(1).GetComponent <Text>()));
            }
        }
예제 #13
0
 public MockGameData(MatchInfo matchinfo   = null, GameServerInfo serverInfo = null, AccountId accountId                 = null,
                     ArenaInfo arenaInfo   = null, BattleTag battleTag       = null, BrawlInfo brawlInfo                 = null,
                     Collection collection = null, Card[] draftChoices       = null, List <Card> packCards               = null,
                     int packId            = 0, DungeonInfo[] dungeonInfo    = null, bool friendlyChallengeDialogVisible = false)
 {
     _matchinfo    = matchinfo;
     _serverInfo   = serverInfo;
     _accountId    = accountId;
     _arenaInfo    = arenaInfo;
     _battleTag    = battleTag;
     _brawlInfo    = brawlInfo;
     _collection   = collection;
     _draftChoices = draftChoices;
     _packCards    = packCards;
     _packId       = packId;
     _dungeonInfo  = dungeonInfo;
     _friendlyChallengeDialogVisible = friendlyChallengeDialogVisible;
 }
예제 #14
0
        private void ProcessPacket(Packet p)
        {
            if (p.Index != (short)ClientPacketIds.ServerList)
            {
                return;
            }

            S.ServerList serverList = new S.ServerList();

            GameServerInfo info = new GameServerInfo()
            {
                Name = "天域归来",
                Port = 7000,
            };

            serverList.servers.Add(info);
            Enqueue(serverList);
        }
예제 #15
0
        public override L2B_RegBattleServer DoResponse(B2L_RegBattleServer request, Client client)
        {
            var server = new GameServerInfo
            {
                Host            = request.ServiceHost,
                Port            = request.ServicePort,
                ServerID        = -1,
                MaxServiceCount = request.MaxBattleCount
            };

            var serverIndex = ServerManager.Singleton.AddBattleServer(client.ID, server);

            server.ServerID      = serverIndex;
            client.UserState     = serverIndex;
            client.HaveAdmission = true;
            client.OnDisconnect += UnRegWhenDisconnect;
            return(new L2B_RegBattleServer {
                Code = ErrorCode.OK, ServiceServerID = serverIndex
            });
        }
        /// <summary>
        /// when game create a channel chat, it will use the public ip and private ip to build the name.
        /// Known game: Worm3d
        /// </summary>
        /// <param name="header"></param>
        /// <param name="serverInfo"></param>
        protected void CheckPrivateIP(List <byte> header, GameServerInfo serverInfo)
        {
            var privateFlagGame = new List <string>()
            {
                "Worm3d"
            };

            if (!privateFlagGame.Contains(_request.GameName))
            {
                return;
            }
            // We already have the localip. Bytes are worng.
            if (serverInfo.ServerData.ContainsKey("localip0"))
            {
                header[0] ^= (byte)GameServerFlags.PrivateIPFlag;
                // there are multiple localip in dictionary we do not know which one is needed here,
                // so we just send the first one.
                byte[] bytesAddress = IPAddress.Parse(serverInfo.ServerData["localip0"]).GetAddressBytes();
                header.AddRange(bytesAddress);
            }
        }
예제 #17
0
    public BattleGate(GameServerInfo serverInfo, int mapID)
    {
        ServerInfo          = serverInfo;
        MapID               = mapID;
        MapConfig           = ExcelConfig.ExcelToJSONConfigManager.Current.GetConfigByID <ExcelConfig.MapData>(MapID);
        player.OnCreateUser = (view) =>
        {
            var character = view as UCharacterView;
            if (UAppliaction.Singleton.UserID == character.UserID)
            {
                ThridPersionCameraContollor.Singleton.lookAt = character.GetBoneByName("Bottom");
                //ThridPersionCameraContollor.Singleton.forwardTrans = view.Character.transform;
                UUIManager.Singleton.ShowMask(false);
                var ui = UUIManager.Singleton.GetUIWindow <Windows.UUIBattle>();
                ui.InitCharacter(character);
            }
        };
        player.OnDeath = (view) =>
        {
            var character = view as UCharacterView;
            if (UAppliaction.Singleton.UserID == character.UserID)
            {
                //Go to Main
                //dead
            }
        };

        player.OnJoined = (initPack) =>
        {
            if (UAppliaction.Singleton.UserID == initPack.UserID)
            {
                startTime       = Time.time;
                ServerStartTime = initPack.TimeNow;
            }
        };

        player.OnDrop = (drop) =>
        {
        };
    }
예제 #18
0
        public override L2G_Reg DoResponse(G2L_Reg request, Client client)
        {
            if (!ProtoTool.CompareVersion(request.Version))
            {
                return(new L2G_Reg {
                    Code = ErrorCode.VersionError
                });
            }


            client.HaveAdmission = true;
            client.UserState     = request.ServerID;
            var server = new GameServerInfo
            {
                ServerID = request.ServerID,
                Host     = request.Host,
                Port     = request.Port
            };
            var success = ServerManager
                          .S.AddGateServer(
                client.ID,
                request.CurrentPlayer,
                server,
                request.ServiceHost,
                request.ServicesProt
                );

            if (!success)
            {
                return(new L2G_Reg {
                    Code = ErrorCode.Error
                });
            }

            client.OnDisconnect += OnDisconnect;
            return(new L2G_Reg {
                Code = ErrorCode.OK
            });
        }
예제 #19
0
    public GameServerInfo FindMatch(PlayerInfo player)
    {
        Dictionary <GameServerInfo, NetworkConnection> candidates = new Dictionary <GameServerInfo, NetworkConnection>();

        foreach (var kvp in servers)
        {
            if (kvp.Key.playerCount < kvp.Key.maxPlayers)
            {
                candidates.Add(kvp.Key, kvp.Value);
            }
        }
        if (candidates.Count > 0)
        {
            GameServerInfo match = candidates.Keys.ToArray()[0];
            AddPlayerToServer(match, player);
            return(match);
        }
        else
        {
            //TODO we should instantiate new server.
            return(null);
        }
    }
        /// <summary>
        /// Add more server info here
        /// the sequence of server info is important
        /// 1.PRIVATE_IP_FLAG length=4
        /// 2.ICMP_IP_FLAG length=4
        /// 3.NONSTANDARD_PORT_FLAG length=2
        /// 4.NONSTANDARD_PRIVATE_PORT_FLAG length=2
        /// </summary>
        /// <param name="flag"></param>
        /// <param name="serverInfo"></param>
        protected void BuildServerInfoHeader(GameServerFlags?flag, GameServerInfo serverInfo)
        {
            List <byte> header = new List <byte>();

            // add key flag
            header.Add((byte)flag);
            // we add server public ip here
            header.AddRange(serverInfo.HostIPAddress.GetAddressBytes());
            // we check host port is standard port or not
            CheckNonStandardPort(header, serverInfo);
            // check if game can directly query information from server
            CheckUnsolicitedUdp(header, serverInfo);
            // we check the natneg flag
            CheckNatNegFlag(header, serverInfo);
            // now we check if there are private ip
            CheckPrivateIP(header, serverInfo);
            // we check private port here
            CheckNonStandardPrivatePort(header, serverInfo);
            // we check icmp support here
            CheckICMPSupport(header, serverInfo);

            _serverListData.AddRange(header);
        }
예제 #21
0
        private IList <ServerInfo> CreateServerInfos()
        {
            if (this.servers == null)
            {
                return(null);
            }

            var result = new List <ServerInfo>();

            foreach (var gameServer in this.servers.OfType <IGameServer>().OrderBy(s => s.Id))
            {
                var serverInfo = new GameServerInfo(gameServer);
                result.Add(serverInfo);
            }

            foreach (var server in this.servers.Where(server => !(server is IGameServer)))
            {
                var serverInfo = new ServerInfo(server);
                result.Add(serverInfo);
            }

            return(result);
        }
예제 #22
0
        private void Gate()
        {
            gclient = new ServerUtility.RequestClient(GateServer.Host, GateServer.Port);
            gclient.UseSendThreadUpdate = true;

            gclient.OnConnectCompleted = (s, e) =>
            {
                if (e.Success)
                {
                    var login = gclient.CreateRequest <C2G_Login, G2C_Login>();
                    login.RequestMessage.Session = sessionKey;
                    login.RequestMessage.UserID  = userID;
                    login.RequestMessage.Version = ProtoTool.GetVersion();
                    login.OnCompleted            = (t1, t2) =>
                    {
                        Debuger.Log(t2);
                    };
                    login.SendRequestSync();

                    var beginBattle = gclient.CreateRequest <C2G_BeginGame, G2C_BeginGame>();
                    beginBattle.RequestMessage.MapID = 1;
                    beginBattle.OnCompleted          = (se, res) =>
                    {
                        if (res.Code == ErrorCode.OK)
                        {
                            BattleServer = res.ServerInfo;
                            gclient.Disconnect();
                            MEvent.Set();
                        }
                    };
                    beginBattle.SendRequestSync();
                }
            };

            gclient.Connect();
        }
예제 #23
0
 public GameServerInfoResponse(string endpoint, GameServerInfo info)
 {
     Endpoint = endpoint;
     Info     = info;
 }
        public static async Task <RoomServerInfo> EnterRoom(CloudFunctionContext context, string roomId)
        {
            //// TODO [bgish]: Verify this is an actual room...
            //// TODO [bgish]: Verify this user has the right to enter this room...

            // Querying Title Data to figure out what server info we should be using
            var gameServerInfoKey = "GameServerInfo";

            var getTitleData = await global::PlayFab.PlayFabServerAPI.GetTitleDataAsync(new global::PlayFab.ServerModels.GetTitleDataRequest
            {
                Keys = new List <string> {
                    gameServerInfoKey
                },
                AuthenticationContext = context.TitleAuthenticationContext,
            });

            GameServerInfo gameServerInfo = JsonUtil.Deserialize <GameServerInfo>(getTitleData.Result.Data[gameServerInfoKey]);

            // Querying if the server info already exists
            RoomServerInfo serverInfo = GetServerInfoForRoom(roomId);

            if (serverInfo == null)
            {
                serverInfo = new RoomServerInfo
                {
                    RoomId    = roomId,
                    SessionId = Guid.NewGuid().ToString("D"),
                    BuildId   = gameServerInfo.BuildId,
                };

                if (AddServerInfoIfDoesNotExist(serverInfo))
                {
                    DateTime start = DateTime.Now;

                    // We were successful registering our ServerInfo, they we need to spin up an actual server and set that data too
                    var request = await PlayFabMultiplayerAPI.RequestMultiplayerServerAsync(new RequestMultiplayerServerRequest
                    {
                        SessionId             = serverInfo.SessionId,
                        BuildId               = serverInfo.BuildId,
                        PreferredRegions      = gameServerInfo.Regions,
                        AuthenticationContext = context.TitleAuthenticationContext,
                    });

                    DateTime end = DateTime.Now;

                    UnityEngine.Debug.Log($"RequestMultiplayerServerRequest Time = {end.Subtract(start).TotalMilliseconds}");

                    serverInfo.FQDN     = request.Result.FQDN;
                    serverInfo.Ports    = request.Result.Ports;
                    serverInfo.Region   = request.Result.Region;
                    serverInfo.ServerId = request.Result.ServerId;

                    if (serverInfo.SessionId != request.Result.SessionId)
                    {
                        UnityEngine.Debug.LogError($"Multiplayer Session Id Changed from {serverInfo.SessionId} to {request.Result.SessionId}");
                        serverInfo.SessionId = request.Result.SessionId;
                    }

                    UpdateServerInfo(serverInfo);

                    return(serverInfo);
                }
                else
                {
                    // NOTE [bgish]: This will fail if the winner has the RequestMultiplayerServerAsync fail due to lack of availability
                    // Someone beat us to the punch and added one before us, so lets poll till we get the server info
                    serverInfo = GetServerInfoForRoom(roomId);

                    int retryCount = 0;
                    while (string.IsNullOrEmpty(serverInfo?.FQDN))
                    {
                        await Task.Delay(100);

                        serverInfo = GetServerInfoForRoom(roomId);
                        retryCount++;

                        if (retryCount > 30)
                        {
                            throw new Exception("Retry Count Max Met!");
                        }
                    }

                    return(serverInfo);
                }
            }
            else
            {
                var getServerInfo = await PlayFabMultiplayerAPI.GetMultiplayerServerDetailsAsync(new GetMultiplayerServerDetailsRequest
                {
                    BuildId               = serverInfo.BuildId,
                    Region                = serverInfo.Region,
                    SessionId             = serverInfo.SessionId,
                    AuthenticationContext = context.TitleAuthenticationContext,
                });

                if (getServerInfo.Error == null)
                {
                    // If it didn't return an error, it should still be good
                    return(serverInfo);
                }
                else
                {
                    // We know this session is no longer valid, so remove it from the cache and get a new one
                    DeleteServerInfoIfDataHasntChanged(serverInfo.RoomId, serverInfo.SessionId, serverInfo.Region);
                    return(await EnterRoom(context, roomId));
                }
            }
        }
예제 #25
0
 public BotPackage(VTankBot bot, GameServerInfo info, Thread thread)
 {
     Bot = bot;
     Server = info;
     Thread = thread;
     state = BotRunnerState.Offline;
     IsShuttingDown = false;
 }
예제 #26
0
 /// <summary>
 /// Connect to the given game server.
 /// </summary>
 /// <param name="bot"></param>
 /// <param name="server"></param>
 private static void ConnectToServer(VTankBot bot, GameServerInfo server)
 {
     bot.ConnectToGameServer(server);
 }
예제 #27
0
 /// <inheritdoc />
 public Task RegisterGameServerAsync(GameServerInfo server)
 {
     this.gameServerController.RegisterGameServer(server);
     return(Task.CompletedTask);
 }
예제 #28
0
        /// <summary>
        /// Connect to a target game server. Throws an exception if something goes
        /// wrong.
        /// </summary>
        /// <param name="server">Game server to connect to.</param>
        public void ConnectToGameServer(GameServerInfo server)
        {
            string key = MainServer.RequestJoinGameServer(server);

            GameServer = new GameCommunicator(
                server.Host, server.Port, server.UseGlacier2);
            GameServer.LogFile = AuthInfo.Username + "GameLog.log";

            if (!GameServer.Connect())
            {
                HandleError("Could not connect to the game server: reason unknown.");
            }

            clientCallback = new ClientI(BotRunner, this, buffer);
            clockCallback = new ClockSync();

            GameServer.RegisterCallback(clientCallback);
            GameServer.RegisterCallback(clockCallback);

            if (!GameServer.JoinServer(key))
            {
                HandleError("Could not join the game server: invalid key.");
            }
            Thread.Sleep(100);

            Debugger.Write("{0}: Connected to the game server! Ping: {1}",
                AuthInfo.Username, server.GetFormattedAverageLatency());

            RefreshPlayerList();
            DownloadAndLoadMap();
            Game.GameModeHandler = CreateGameHandler(GameMode);
            GameServer.Ready();
        }
예제 #29
0
 public GMainGate(GameServerInfo gateServer)
 {
     ServerInfo = gateServer;
 }
예제 #30
0
 /// <summary>
 /// Open a connection to an instance of Theater. Uses a timeout of 10 seconds.
 /// </summary>
 /// <param name="server">Game server to join.</param>
 public static void ConnectToTheater(GameServerInfo server)
 {
     ConnectToTheater(server, 10000);
 }
예제 #31
0
        /// <summary>
        /// Unloads content.
        /// </summary>
        public override void UnloadContent()
        {
            if (thread.IsAlive)
            {
                try
                {
                    thread.Interrupt();
                }
                catch (Exception e)
                {
                    ServiceManager.Game.Console.DebugPrint(
                        "[ERROR] At LoadingScreenState#UnloadContent(): {0}",
                        e.Message);
                }
            }

            if (futureGame != null)
            {
                ServiceManager.Game.BackgroundMovie.Pause();
                ServiceManager.MP3Player.Stop();
                ServiceManager.MP3Player.PlayPlaylist();
                futureGame.OnGameFinished += new GamePlayState.GameFinishHandler(OnGameFinished);
            }

            currentMap = null;
            currentMapInstance = null;
            thread = null;
            server = null;
            form = null;
            futureGame = null;
            clientCallback = null;
            buffer = null;
        }
예제 #32
0
        private void AddQueueEvent(QueueEvent.Type queueType, int minSeconds = 0, int maxSeconds = 0, int bnetError = 0, GameServerInfo gsInfo = null)
        {
            QueueEvent item        = new QueueEvent(queueType, minSeconds, maxSeconds, bnetError, gsInfo);
            object     queueEvents = this.m_queueEvents;

            lock (queueEvents)
            {
                this.m_queueEvents.Enqueue(item);
            }
        }
예제 #33
0
        public void GameEntryHandler(Notification notification)
        {
            base.ApiLog.LogDebug("GAME_ENTRY");
            string host         = null;
            int    port         = 0;
            string stringValue  = null;
            int    intValue     = 0;
            int    num          = 0;
            string str          = null;
            bool   boolValue    = false;
            string stringValue1 = null;

            foreach (bnet.protocol.attribute.Attribute attributeList in notification.AttributeList)
            {
                if (attributeList.Name.Equals("connection_info") && attributeList.Value.HasMessageValue)
                {
                    ConnectInfo connectInfo = ConnectInfo.ParseFrom(attributeList.Value.MessageValue);
                    host = connectInfo.Host;
                    port = connectInfo.Port;
                    if (connectInfo.HasToken)
                    {
                        str = Encoding.UTF8.GetString(connectInfo.Token);
                    }
                    foreach (bnet.protocol.attribute.Attribute attribute in connectInfo.AttributeList)
                    {
                        if (attribute.Name.Equals("version") && attribute.Value.HasStringValue)
                        {
                            stringValue = attribute.Value.StringValue;
                        }
                        else if (attribute.Name.Equals("game") && attribute.Value.HasIntValue)
                        {
                            intValue = (int)attribute.Value.IntValue;
                        }
                        else if (attribute.Name.Equals("id") && attribute.Value.HasIntValue)
                        {
                            num = (int)attribute.Value.IntValue;
                        }
                        else if (!attribute.Name.Equals("resumable") || !attribute.Value.HasBoolValue)
                        {
                            if (!attribute.Name.Equals("spectator_password") || !attribute.Value.HasStringValue)
                            {
                                continue;
                            }
                            stringValue1 = attribute.Value.StringValue;
                        }
                        else
                        {
                            boolValue = attribute.Value.BoolValue;
                        }
                    }
                }
                else if (!attributeList.Name.Equals("game_handle") || !attributeList.Value.HasMessageValue)
                {
                    if (!attributeList.Name.Equals("sender_id") || !attributeList.Value.HasMessageValue)
                    {
                        continue;
                    }
                    base.ApiLog.LogDebug("sender_id");
                }
                else
                {
                    GameHandle gameHandle = GameHandle.ParseFrom(attributeList.Value.MessageValue);
                    this.m_battleNet.Channel.JoinChannel(gameHandle.GameId, ChannelAPI.ChannelType.GAME_CHANNEL);
                }
            }
            GameServerInfo gameServerInfo = new GameServerInfo()
            {
                Address           = host,
                Port              = port,
                AuroraPassword    = str,
                Version           = stringValue,
                GameHandle        = intValue,
                ClientHandle      = (long)num,
                Resumable         = boolValue,
                SpectatorPassword = stringValue1
            };

            this.AddQueueEvent(QueueEvent.Type.QUEUE_GAME_STARTED, 0, 0, 0, gameServerInfo);
        }
예제 #34
0
        private void AddQueueEvent(QueueEvent.Type queueType, int minSeconds = 0, int maxSeconds = 0, int bnetError = 0, GameServerInfo gsInfo = null)
        {
            QueueEvent queueEvent   = new QueueEvent(queueType, minSeconds, maxSeconds, bnetError, gsInfo);
            object     mQueueEvents = this.m_queueEvents;

            Monitor.Enter(mQueueEvents);
            try
            {
                this.m_queueEvents.Enqueue(queueEvent);
            }
            finally
            {
                Monitor.Exit(mQueueEvents);
            }
        }
예제 #35
0
 public void addGameServerInfo(GameServerInfo server)
 {
     GameServerInfoHolder._servers.Add(server);
 }
예제 #36
0
 /// <summary>
 /// Event handler for when a user selects a server
 /// </summary>
 /// <param name="obj">The highlighted Field in the Listview. Used</param>
 /// <param name="e">Not used</param>
 void SelectionChanged(object sender, TomShane.Neoforce.Controls.EventArgs e)
 {
     form.Play.Enabled = true;
     string[] serverInfo = form.Items[form.SelectedIndex];
     foreach (GameServerInfo server in serverList)
     {
         if (server.Name == serverInfo[0])
         {
             selectedServer = server;
         }
     }
 }
예제 #37
0
        /// <summary>
        /// Open a connection to an instance of Theater.
        /// </summary>
        /// <param name="server">Game server to join.</param>
        /// <param name="timeout">Timeout in milliseconds.</param>
        public static void ConnectToTheater(GameServerInfo server, long timeout)
        {
            if (Echelon == null)
            {
                throw new Exception("You must connect to Echelon first.");
            }

            if (Theater == null)
            {
                try
                {
                    Theater = new GameCommunicator(
                        server.Host, server.Port, server.UseGlacier2, timeout);
                    if (!Theater.Connect())
                    {
                        Theater.Disconnect();
                        Theater = null;

                        throw new Exception("Unable to connect to " + server.Host + ".");
                    }
                }
                catch (Exception)
                {
                    Theater = null;
                    throw;
                }
            }
            else
            {
                throw new Exception("The communicator has already been created.");
            }
        }
예제 #38
0
        //开始进入战斗
        internal ErrorCode BeginBattle(
            long userID,
            int mapID, int serverID, out GameServerInfo serverInfo)
        {
            serverInfo = null;
            var battleServer = ServerManager.Singleton.GetFreeBattleServerID();

            if (battleServer == null)
            {
                return(ErrorCode.NOFreeBattleServer);
            }
            UserServerInfo user;

            if (_servers.TryToGetValue(userID, out user))
            {
                var task = new Task_L2B_ExitUser {
                    UserID = user.UserID
                };
                var b       = ServerManager.Singleton.GetBattleServerMappingByServerID(user.BattleServerID);
                var bClient = Appliaction.Current.GetServerConnectByClientID(b.ClientID);
                if (bClient != null)
                {
                    NetProtoTool.SendTask(bClient, task);
                    //bClient.SendMessage(m);
                }
                return(ErrorCode.PlayerIsInBattle);
            }

            var su = _servers.Add(
                userID,
                new UserServerInfo
            {
                MapID          = mapID,
                BattleServerID = battleServer.ServerInfo.ServerID,
                GServerID      = serverID,
                UserID         = userID
            });

            if (su)
            {
                serverInfo = battleServer.ServerInfo;
                var gateserver = ServerManager.Singleton.GetGateServerMappingByServerID(serverID);
                var task       = new Task_L2B_StartBattle
                {
                    MapID = mapID,
                    Users = new List <PlayerServerInfo> {
                        new PlayerServerInfo {
                            UserID      = userID,
                            ServerID    = serverID,
                            ServiceHost = gateserver.ServiceHost,
                            ServicePort = gateserver.ServicePort
                        }
                    }
                };
                //task
                //var message = NetProtoTool.ToNetMessage(XNet.Libs.Net.MessageClass.Task, task);
                var serverConnect = Appliaction.Current.GetServerConnectByClientID(battleServer.ClientID);
                if (serverConnect == null)
                {
                    _servers.Remove(userID);
                    return(ErrorCode.BattleServerHasDisconnect);
                }
                NetProtoTool.SendTask(serverConnect, task);
                //serverConnect.SendMessage(message);
                return(Proto.ErrorCode.OK);
            }
            else
            {
                return(Proto.ErrorCode.PlayerIsInBattle);
            }
        }