public PeerHandler(Socket socket, PeerInfo info, Tracker tracker) { this.tracker = tracker; this.socket = socket; this.info = info; this.isAlive = true; this.isAliveTimer = new System.Timers.Timer(GameConstant.connectionTimeOut); this.isAliveTimer.Elapsed += new ElapsedEventHandler(dead); this.isAliveTimer.Start(); }
private void dead(object source, ElapsedEventArgs e) { tracker.removeDeadPeer(this.info.getID()); this.isAliveTimer.Stop(); this.socket = null; this.info = null; this.isAliveTimer = null; this.tracker = null; }
static void Main(string[] args) { Tracker tracker = new Tracker(GameConstant.trackerPort); tracker.start(); string cmd = String.Empty; string[] cmds; System.Console.WriteLine("GunbondGame Tracker v1.0"); while (cmd != "shutdown") { System.Console.Write(">"); cmd = System.Console.ReadLine(); cmds = Regex.Split(cmd, " "); if (cmds[0] == "max_peer") { tracker.setMaxPeer(Convert.ToInt32(cmds[1])); } if (cmds[0] == "max_room") { tracker.setMaxRoom(Convert.ToInt32(cmds[1])); } if (cmds[0] == "log") { if (cmds[1] == "on") tracker.setLog(true); else if (cmds[1] == "off") tracker.setLog(false); else if (cmds[1] == "keepalive") { if (cmds[2] == "on") tracker.setLogKeepAlive(true); else if (cmds[2] == "off") tracker.setLogKeepAlive(false); } } if (cmds[0] == "room_list") { System.Console.WriteLine("ROOM LIST"); foreach (Room room in tracker.getRoomList()) { System.Console.WriteLine(room.toStringWithoutPeers()); } } if (cmds[0] == "peer_list") { System.Console.WriteLine("PEER LIST"); foreach (PeerHandler peer in tracker.peerList) { System.Console.WriteLine(peer.info); } } if (cmds[0] == "room_list_full") { System.Console.WriteLine("ROOM LIST"); foreach (Room room in tracker.getRoomList()) { System.Console.WriteLine(room); } } } }