public void Parse(GameClientPacket packet) { if (_isError) return; CtosMessage msg = packet.ReadCtos(); switch (msg) { case CtosMessage.PlayerInfo: OnPlayerInfo(packet); break; case CtosMessage.JoinGame: OnJoinGame(packet); break; } if (!IsAuthentified) return; switch (msg) { case CtosMessage.Chat: OnChat(packet); break; case CtosMessage.HsToDuelist: Game.MoveToDuelist(this); break; case CtosMessage.HsToObserver: Game.MoveToObserver(this); break; case CtosMessage.LeaveGame: Game.RemovePlayer(this); break; case CtosMessage.HsReady: Game.SetReady(this, true); break; case CtosMessage.HsNotReady: Game.SetReady(this, false); break; case CtosMessage.HsKick: OnKick(packet); break; case CtosMessage.HsStart: Game.StartDuel(this); break; case CtosMessage.HandResult: OnHandResult(packet); break; case CtosMessage.TpResult: OnTpResult(packet); break; case CtosMessage.UpdateDeck: OnUpdateDeck(packet); break; case CtosMessage.Response: OnResponse(packet); break; case CtosMessage.Surrender: Game.Surrender(this, 0); break; } }
private void OnPlayerInfo(GameClientPacket packet) { if (Name != null) { return; } Name = packet.ReadUnicode(20); }
private void NetworkReceive() { if (_client.Available >= 2 && _receivedLen == -1) { _receivedLen = _reader.ReadUInt16(); } if (_receivedLen != -1 && _client.Available >= _receivedLen) { GameClientPacket packet = new GameClientPacket(_reader.ReadBytes(_receivedLen)); _receivedLen = -1; lock (_recvQueue) _recvQueue.Enqueue(packet); } }
private void OnResponse(GameClientPacket packet) { if (Game.State != GameState.Duel) { return; } if (State != PlayerState.Response) { return; } byte[] resp = packet.ReadToEnd(); if (resp.Length > 64) { return; } State = PlayerState.None; Game.SetResponse(resp); }
private void OnUpdateDeck(GameClientPacket packet) { if (Type == (int)PlayerType.Observer) { return; } Deck deck = new Deck(); int main = packet.ReadInt32(); int side = packet.ReadInt32(); for (int i = 0; i < main; i++) { deck.AddMain(packet.ReadInt32()); } for (int i = 0; i < side; i++) { deck.AddSide(packet.ReadInt32()); } if (Game.State == GameState.Lobby) { Deck = deck; Game.IsReady[Type] = false; } else if (Game.State == GameState.Side) { if (Game.IsReady[Type]) { return; } if (!Deck.Check(deck)) { GameServerPacket error = new GameServerPacket(StocMessage.ErrorMsg); error.Write((byte)3); error.Write(0); Send(error); return; } Deck = deck; Game.IsReady[Type] = true; Send(new GameServerPacket(StocMessage.DuelStart)); Game.MatchSide(); } }
private void OnJoinGame(GameClientPacket packet) { if (Name == null || Type != (int)PlayerType.Undefined) { return; } int version = packet.ReadInt16(); if (version != Program.ProVersion) { return; } packet.ReadInt32();//gameid packet.ReadInt16(); Game.AddPlayer(this); IsAuthentified = true; }
private void NetworkParse() { int count; lock (_recvQueue) count = _recvQueue.Count; while (count > 0) { GameClientPacket packet = null; lock (_recvQueue) { if (_recvQueue.Count > 0) { packet = _recvQueue.Dequeue(); } count = _recvQueue.Count; } if (packet != null) { Player.Parse(packet); } } }
private void NetworkReceive() { if (_client.Available >= 2 && _receivedLen == -1) _receivedLen = _reader.ReadUInt16(); if (_receivedLen != -1 && _client.Available >= _receivedLen) { GameClientPacket packet = new GameClientPacket(_reader.ReadBytes(_receivedLen)); _receivedLen = -1; lock (_recvQueue) _recvQueue.Enqueue(packet); } }
private void OnUpdateDeck(GameClientPacket packet) { if (Type == (int)PlayerType.Observer) return; Deck deck = new Deck(); int main = packet.ReadInt32(); int side = packet.ReadInt32(); for (int i = 0; i < main; i++) deck.AddMain(packet.ReadInt32()); for (int i = 0; i < side; i++) deck.AddSide(packet.ReadInt32()); if (Game.State == GameState.Lobby) { Deck = deck; Game.IsReady[Type] = false; } else if (Game.State == GameState.Side) { if (Game.IsReady[Type]) return; if (!Deck.Check(deck)) { GameServerPacket error = new GameServerPacket(StocMessage.ErrorMsg); error.Write((byte)3); error.Write(0); Send(error); return; } Deck = deck; Game.IsReady[Type] = true; Send(new GameServerPacket(StocMessage.DuelStart)); Game.MatchSide(); } }
private void OnResponse(GameClientPacket packet) { if (Game.State != GameState.Duel) return; if (State != PlayerState.Response) return; byte[] resp = packet.ReadToEnd(); if (resp.Length > 64) return; State = PlayerState.None; Game.SetResponse(resp); }
private void OnHandResult(GameClientPacket packet) { int res = packet.ReadByte(); Game.HandResult(this, res); }
private void OnTpResult(GameClientPacket packet) { bool tp = packet.ReadByte() != 0; Game.TpResult(this, tp); }
private void OnChat(GameClientPacket packet) { string msg = packet.ReadUnicode(256); Game.Chat(this, msg); }
private void OnKick(GameClientPacket packet) { int pos = packet.ReadByte(); Game.KickPlayer(this, pos); }
private void OnJoinGame(GameClientPacket packet) { if (Name == null || Type != (int)PlayerType.Undefined) return; int version = packet.ReadInt16(); if (version != Program.ProVersion) return; packet.ReadInt32();//gameid packet.ReadInt16(); Game.AddPlayer(this); IsAuthentified = true; }
private void OnPlayerInfo(GameClientPacket packet) { if (Name != null) return; Name = packet.ReadUnicode(20); }
public void Parse(GameClientPacket packet) { if (_isError) { return; } CtosMessage msg = packet.ReadCtos(); switch (msg) { case CtosMessage.PlayerInfo: OnPlayerInfo(packet); break; case CtosMessage.JoinGame: OnJoinGame(packet); break; } if (!IsAuthentified) { return; } switch (msg) { case CtosMessage.Chat: OnChat(packet); break; case CtosMessage.HsToDuelist: Game.MoveToDuelist(this); break; case CtosMessage.HsToObserver: Game.MoveToObserver(this); break; case CtosMessage.LeaveGame: Game.RemovePlayer(this); break; case CtosMessage.HsReady: Game.SetReady(this, true); break; case CtosMessage.HsNotReady: Game.SetReady(this, false); break; case CtosMessage.HsKick: OnKick(packet); break; case CtosMessage.HsStart: Game.StartDuel(this); break; case CtosMessage.HandResult: OnHandResult(packet); break; case CtosMessage.TpResult: OnTpResult(packet); break; case CtosMessage.UpdateDeck: OnUpdateDeck(packet); break; case CtosMessage.Response: OnResponse(packet); break; case CtosMessage.Surrender: Game.Surrender(this, 0); break; } }