public void 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; } } } connection.Send(data); }
static void Main(string[] args) { try { GameServerListManager.Initialize(); var server = new GameProxy(); Console.WriteLine("Press Enter to exit..."); Console.ReadLine(); } catch (Exception ex) { TraceLog.WriteError("Main error:{0}", ex); } }
private void DoRefreshGameServer(object state) { try { GameServerListManager.Initialize(s => { string key = GetKey(s.GameID, s.ID); TraceLog.ReleaseWrite("Reflesh server:{0} setting.", key); GameServerConnection value; if (serversPool.TryRemove(key, out value)) { value.Stop(); } }); } catch (Exception) { } }
static void Main(string[] args) { try { var dict = new CacheList <int>(); dict.Add(1); string js = dict.ToJson(); var temp = js.ParseJson <CacheList <int> >(); if (temp == null) { } GameServerListManager.Initialize(); var server = new GameProxy(); Console.WriteLine("Press Enter to exit..."); Console.ReadLine(); } catch (Exception ex) { TraceLog.WriteError("Main error:{0}", ex); } }