예제 #1
0
        public bool Send(int gameId, int serverId, byte[] data)
        {
            GameServerConnection connection;
            string key = GetKey(gameId, serverId);

            if (!serversPool.TryGetValue(key, out connection))
            {
                lock (serversPool)
                {
                    if (!serversPool.TryGetValue(key, out connection))
                    {
                        var serverInfo = GameServerListManager.Find(gameId, serverId);
                        //需要实现的,加载服务器列表到proxy pool中,必须实现
                        if (serverInfo == null)
                        {
                            throw new ApplicationException(string.Format("游戏id={0}服务器id={1}不存在。", gameId, serverId));
                        }
                        if (!serverInfo.IsEnable)
                        {
                            throw new ApplicationException(string.Format("游戏id={0}服务器id={1}未开放。", gameId, serverId));
                        }
                        var arr = !string.IsNullOrEmpty(serverInfo.IntranetAddress)
                            ? serverInfo.IntranetAddress.Split(':')
                            : serverInfo.ServerUrl.Split(':');
                        var ip   = arr[0];
                        var port = Convert.ToInt32(arr[1]);
                        connection       = new GameServerConnection(ip, port, proxy);
                        serversPool[key] = connection;
                    }
                }
            }

            return(connection.Send(data));
        }
예제 #2
0
        public void Send(int gameId, int serverId, byte[] data)
        {
            GameServerConnection connection;
            var key = string.Format("{0}_{1}", gameId, serverId);

            if (!serversPool.TryGetValue(key, out connection))
            {
                lock (serversPool)
                {
                    if (!serversPool.TryGetValue(key, out connection))
                    {
                        var serverInfo = GameServerListManager.Current.Find(gameId, serverId);
                        //需要实现的,加载服务器列表到proxy pool中,必须实现
                        if (serverInfo == null)
                        {
                            throw new ApplicationException(string.Format("游戏id={0}服务器id={1}不存在。", gameId, serverId));
                        }
                        if (!serverInfo.IsEnable)
                        {
                            throw new ApplicationException(string.Format("游戏id={0}服务器id={1}未开放。", gameId, serverId));
                        }
                        var arr  = serverInfo.ServerUrl.Split(':');
                        var ip   = arr[0];
                        var port = Convert.ToInt32(arr[1]);
                        connection       = new GameServerConnection(ip, port, proxy);
                        serversPool[key] = connection;
                    }
                }
            }

            connection.Send(data);
        }
예제 #3
0
        public void Send(int gameId, int serverId, byte[] data)
        {
            GameServerConnection connection;
            var key = string.Format("{0}_{1}", gameId, serverId);
            if (!serversPool.TryGetValue(key, out connection))
            {
                lock (serversPool)
                {
                    if (!serversPool.TryGetValue(key, out connection))
                    {
                        var serverInfo = GameServerListManager.Current.Find(gameId, serverId);
                        //需要实现的,加载服务器列表到proxy pool中,必须实现
                        if (serverInfo == null) throw new ApplicationException(string.Format("游戏id={0}服务器id={1}不存在。", gameId, serverId));
                        if (!serverInfo.IsEnable) throw new ApplicationException(string.Format("游戏id={0}服务器id={1}未开放。", gameId, serverId));
                        var arr = serverInfo.ServerUrl.Split(':');
                        var ip = arr[0];
                        var port = Convert.ToInt32(arr[1]);
                        connection = new GameServerConnection(ip, port, proxy);
                        serversPool[key] = connection;
                    }
                }
            }

            connection.Send(data);
        }
예제 #4
0
        public bool Send(int gameId, int serverId, byte[] data)
        {
            GameServerConnection connection;
            string key = GetKey(gameId, serverId);
            if (!serversPool.TryGetValue(key, out connection))
            {
                lock (serversPool)
                {
                    if (!serversPool.TryGetValue(key, out connection))
                    {
                        var serverInfo = GameServerListManager.Find(gameId, serverId);
                        //需要实现的,加载服务器列表到proxy pool中,必须实现
                        if (serverInfo == null)
                            throw new ApplicationException(string.Format("游戏id={0}服务器id={1}不存在。", gameId, serverId));
                        if (!serverInfo.IsEnable)
                            throw new ApplicationException(string.Format("游戏id={0}服务器id={1}未开放。", gameId, serverId));
                        var arr = !string.IsNullOrEmpty(serverInfo.IntranetAddress)
                            ? serverInfo.IntranetAddress.Split(':')
                            : serverInfo.ServerUrl.Split(':');
                        var ip = arr[0];
                        var port = Convert.ToInt32(arr[1]);
                        connection = new GameServerConnection(ip, port, proxy);
                        serversPool[key] = connection;
                    }
                }
            }

            return connection.Send(data);
        }