void SideTimer_Elapsed(object sender, ElapsedEventArgs e) { if (!(sender is MyTimer)) { return; } MyTimer timer = (MyTimer)sender; if (room.State != GameState.Side) { timer.CheckStop(); return; } long second = timer.Second; long maxtime = timer.MaxTime; if (second == (maxtime - 30) || second == (maxtime - 60)) { room.ServerMessage(string.Format(Messages.MSG_TIP_TIME, (maxtime - second))); } if (timer.CheckStop()) { if (!room.IsReady[0] && !room.IsReady[1]) { room.State = GameState.End; room.End(); return; } room.Surrender(!room.IsReady[0] ? room.Players[0]:room.Players[1], 3, true); room.State = GameState.End; room.End(); } }
void StartingTimer_Elapsed(object sender, ElapsedEventArgs e) { if (!(sender is MyTimer)) { return; } MyTimer timer = (MyTimer)sender; if (room.State != GameState.Starting) { timer.CheckStop(); return; } if (room.IsTpSelect) { long second = timer.Second; long maxtime = timer.MaxTime; if ((maxtime - second) == 15 || (maxtime - second) < 6) { room.ServerMessage(string.Format(Messages.MSG_TIP_TIME, (maxtime - second))); } } if (timer.CheckStop()) { room.Surrender(room.Players[room.m_startplayer], 3, true); room.State = GameState.End; room.End(); } }
void HandTimer_Elapsed(object sender, ElapsedEventArgs e) { if (!(sender is MyTimer)) { return; } MyTimer timer = (MyTimer)sender; if (room.State != GameState.Hand) { timer.CheckStop(); return; } long second = timer.Second; long maxtime = timer.MaxTime; int currentTick = (int)(maxtime - second); if (currentTick == 30 || currentTick == 15) { room.ServerMessage(string.Format(Messages.MSG_TIP_TIME, currentTick)); } if (timer.CheckStop()) { if (room.m_handResult[0] != 0) { room.Surrender(room.Players[1], 3, true); } else if (room.m_handResult[1] != 0) { room.Surrender(room.Players[0], 3, true); } else { room.State = GameState.End; room.End(); return; } if (room.m_handResult[0] == 0 && room.m_handResult[1] == 0) { room.State = GameState.End; room.End(); return; } else { room.Surrender(room.Players[1 - room.m_lastresponse], 3, true); } } }
public GameSession(Connection <GameSession> client, int version, int timeout) { this.m_client = client; //Asynchronous send this.Type = (int)PlayerType.Undefined; this.State = PlayerState.None; this.ClientVersion = version; if (timeout <= 0) { timeout = 15; } MyTimer CheckTimer = new MyTimer(1000, timeout); CheckTimer.AutoReset = true; CheckTimer.Elapsed += delegate { if (!string.IsNullOrEmpty(Name)) { CheckTimer.Stop(); CheckTimer.Close(); } if (CheckTimer.CheckStop()) { //Timeout is automatically disconnected CloseAsync(); CheckTimer.Close(); } }; }
public GameSession(Connection<GameSession> client, int version, int timeout) { this.m_client = client; //异步发送 this.Type = (int)PlayerType.Undefined; this.State = PlayerState.None; this.ClientVersion = version; if (timeout <= 0) { timeout = 15; } MyTimer CheckTimer = new MyTimer(1000, timeout); CheckTimer.AutoReset = true; CheckTimer.Elapsed += delegate { if (!string.IsNullOrEmpty(Name)) { CheckTimer.Stop(); CheckTimer.Close(); } if (CheckTimer.CheckStop()) { //超时自动断开 CloseAsync(); CheckTimer.Close(); } }; }
public Session(Connection<Session> client, RoomServer server, int timeout = 15) { this.Client = client; this.Client.Tag = this; this.Server = server; MyTimer CheckTimer = new MyTimer(1000, timeout); CheckTimer.AutoReset = true; CheckTimer.Elapsed += delegate { if (!string.IsNullOrEmpty(Name)) { CheckTimer.Stop(); CheckTimer.Close(); } if (CheckTimer.CheckStop()) { //超时自动断开 Close(); CheckTimer.Close(); } }; }
public Session(Connection <Session> client, RoomServer server, int timeout = 15) { this.Client = client; this.Client.Tag = this; this.Server = server; MyTimer CheckTimer = new MyTimer(1000, timeout); CheckTimer.AutoReset = true; CheckTimer.Elapsed += delegate { if (!string.IsNullOrEmpty(Name)) { CheckTimer.Stop(); CheckTimer.Close(); } if (CheckTimer.CheckStop()) { //超时自动断开 Close(); CheckTimer.Close(); } }; }