private void OnJoinGame(GameServerPacket packet) { GameClientPacket deck = new GameClientPacket(CtosMessage.UpdateDeck); deck.Write(Deck.Cards.Count + Deck.ExtraCards.Count); deck.Write(Deck.SideCards.Count); foreach (CardData card in Deck.Cards) { deck.Write(card.Id); } foreach (CardData card in Deck.ExtraCards) { deck.Write(card.Id); } foreach (CardData card in Deck.SideCards) { deck.Write(card.Id); } if (!Game.IsCheckmate) { Connection.Send(deck); } else { Connection.Send(CtosMessage.HsToDuelist); Connection.Send(deck); Connection.Send(CtosMessage.HsReady); } }
private void OnJoinGame(GameServerPacket packet) { uint banlist = packet.ReadUInt32(); int rule = packet.ReadByte(); int mode = packet.ReadByte(); //TODO tag _room.IsTag = mode == 2; Logger.WriteLine("istag = " + _room.IsTag); GameClientPacket deck = new GameClientPacket(CtosMessage.UpdateDeck); deck.Write(Deck.Cards.Count + Deck.ExtraCards.Count); deck.Write(Deck.SideCards.Count); foreach (Card card in Deck.Cards) { deck.Write(card.Id); } foreach (Card card in Deck.ExtraCards) { deck.Write(card.Id); } foreach (Card card in Deck.SideCards) { deck.Write(card.Id); } Connection.Send(deck); }
public static GameConfig Build(GameClientPacket packet) { GameConfig config = new GameConfig(); config.LfList = BanlistManager.GetIndex(packet.ReadUInt32()); config.BanList = BanlistManager.GetName(config.LfList); config.Rule = packet.ReadByte(); config.Mode = packet.ReadByte(); config.EnablePriority = Convert.ToBoolean(packet.ReadByte()); config.NoCheckDeck = Convert.ToBoolean(packet.ReadByte()); config.NoShuffleDeck = Convert.ToBoolean(packet.ReadByte()); //C++ padding: 5 bytes + 3 bytes = 8 bytes for (int i = 0; i < 3; i++) packet.ReadByte(); config.StartLp = packet.ReadInt32(); config.StartHand = packet.ReadByte(); config.DrawCount = packet.ReadByte(); config.GameTimer = packet.ReadInt16(); packet.ReadUnicode(20); config.Name = packet.ReadUnicode(30); if (string.IsNullOrEmpty(config.Name)) config.Name = RoomManager.NewRandomRoomName(); config.RoomString = config.Name; return config; }
private void OnSelectCounter(GameServerPacket packet) { packet.ReadByte(); // player int type = packet.ReadInt16(); int quantity = packet.ReadByte(); IList <ClientCard> cards = new List <ClientCard>(); IList <int> counters = new List <int>(); int count = packet.ReadByte(); for (int i = 0; i < count; ++i) { packet.ReadInt32(); // card id int player = GetLocalPlayer(packet.ReadByte()); CardLocation loc = (CardLocation)packet.ReadByte(); int seq = packet.ReadByte(); int num = packet.ReadByte(); cards.Add(_duel.GetCard(player, loc, seq)); counters.Add(num); } IList <int> used = _ai.OnSelectCounter(type, quantity, cards, counters); byte[] result = new byte[used.Count]; for (int i = 0; i < quantity; ++i) { result[i] = (byte)used[i]; } GameClientPacket reply = new GameClientPacket(CtosMessage.Response); reply.Write(result); Connection.Send(reply); }
public void Chat(string message) { byte[] content = Encoding.Unicode.GetBytes(message + "\0"); GameClientPacket chat = new GameClientPacket(CtosMessage.Chat); chat.Write(content); Connection.Send(chat); }
private void OnSelectSum(GameServerPacket packet) { packet.ReadByte(); // mode packet.ReadByte(); // player int sumval = packet.ReadInt32(); int min = packet.ReadByte(); int max = packet.ReadByte(); IList <ClientCard> cards = new List <ClientCard>(); int count = packet.ReadByte(); for (int i = 0; i < count; ++i) { int cardId = packet.ReadInt32(); int player = GetLocalPlayer(packet.ReadByte()); CardLocation loc = (CardLocation)packet.ReadByte(); int seq = packet.ReadByte(); ClientCard card = _duel.GetCard(player, loc, seq); if (card != null) { if (cardId != 0 && card.Id != cardId) { card.SetId(cardId); } cards.Add(card); } packet.ReadInt32(); } IList <ClientCard> selected = _ai.OnSelectSum(cards, sumval, min, max); byte[] result = new byte[selected.Count + 1]; result[0] = (byte)selected.Count; for (int i = 0; i < selected.Count; ++i) { int id = 0; for (int j = 0; j < count; ++j) { if (cards[j] == null) { continue; } if (cards[j].Equals(selected[i])) { id = j; break; } } result[i + 1] = (byte)id; } GameClientPacket reply = new GameClientPacket(CtosMessage.Response); reply.Write(result); Connection.Send(reply); }
public void Start() { Connection = new GameConnection(IPAddress.Parse(_serverHost), _serverPort); _behavior = new GameBehavior(this); GameClientPacket packet = new GameClientPacket(CtosMessage.PlayerInfo); packet.Write(Username, 20); Connection.Send(packet); byte[] junk = { 0xCC, 0xCC, 0x00, 0x00, 0x00, 0x00 }; packet = new GameClientPacket(CtosMessage.JoinGame); packet.Write(Program.ProVersion); packet.Write(junk); packet.Write(_roomInfos, 30); Connection.Send(packet); }
public void Start() { Connection = new AIGameConnection(IPAddress.Parse(_serverHost), _serverPort); _behavior = new GameBehavior(this); GameClientPacket packet = new GameClientPacket(CtosMessage.PlayerInfo); packet.Write(Username, 20); Connection.Send(packet); byte[] junk = { 0xCC, 0xCC, 0x00, 0x00, 0x00, 0x00 }; packet = new GameClientPacket(CtosMessage.JoinGame); packet.Write((short)Program.ProVersion); packet.Write(junk); packet.Write(_roomInfos, 30); Deck deck = Deck.Load(Deck_); if (deck == null) { Logger.WriteLine("read deck fail."); Connection.Close(); return; } packet.Write((byte)CtosMessage.UpdateDeck); packet.Write(deck.Cards.Count); packet.Write(deck.SideCards.Count); foreach (var k in deck.Cards) { packet.Write(k.Id); } foreach (var k in deck.SideCards) { packet.Write(k.Id); } packet.Write((byte)CtosMessage.HsReady); Connection.Send(packet); Logger.WriteLine("send deck"); }
public void Start() { Connection = new GameConnection(IPAddress.Parse(m_server.ServerAddress), m_server.ServerPort); m_behavior = new GameBehavior(this); GameClientPacket packet = new GameClientPacket(CtosMessage.PlayerInfo); packet.Write(Program.Config.Username + "$" + (IsCheckmate ? Program.Config.Password : DevClient.Token.ToString()), 20); Connection.Send(packet); byte[] junk = { 0xCC, 0xCC, 0x00, 0x00, 0x00, 0x00 }; packet = new GameClientPacket(CtosMessage.JoinGame); packet.Write(Version); packet.Write(junk); packet.Write(m_roomInfos, 30); Connection.Send(packet); }
private void OnJoinGame(GameServerPacket packet) { GameClientPacket deck = new GameClientPacket(CtosMessage.UpdateDeck); deck.Write(Deck.Cards.Count + Deck.ExtraCards.Count); deck.Write(Deck.SideCards.Count); foreach (CardData card in Deck.Cards) { deck.Write(card.Id); } foreach (CardData card in Deck.ExtraCards) { deck.Write(card.Id); } foreach (CardData card in Deck.SideCards) { deck.Write(card.Id); } Connection.Send(deck); }
private void OnChangeSide(GameServerPacket packet) { GameClientPacket deck = new GameClientPacket(CtosMessage.UpdateDeck); deck.Write(Deck.Cards.Count + Deck.ExtraCards.Count); deck.Write(Deck.SideCards.Count); foreach (Card card in Deck.Cards) { deck.Write(card.Id); } foreach (Card card in Deck.ExtraCards) { deck.Write(card.Id); } foreach (Card card in Deck.SideCards) { deck.Write(card.Id); } Connection.Send(deck); Logger.WriteLine("onChangeSide"); }
public static void OnHandResult(GameSession client, GameClientPacket packet){ int res = packet.ReadByte(); if(client.Game!=null) client.Game.HandResult(client, res); }
public static void OnSurrender(GameSession client, GameClientPacket packet){ if(client.Game!=null) client.Game.Surrender(client, 0); }
public static void OnResponse(GameSession client, GameClientPacket packet){ if (client.Game==null||client.Game.State != GameState.Duel) return; if (client.State != PlayerState.Response) return; byte[] resp = packet.ReadToEnd(); if (resp.Length > 64) return; client.State = PlayerState.None; client.Game.SetResponse(resp); }
public static void OnUpdateDeck(GameSession client, GameClientPacket packet){ if (client.Game==null||client.Type == (int)PlayerType.Observer||client.Type == (int)PlayerType.Undefined) 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 (client.Game.State == GameState.Lobby) { client.Deck = deck; client.Game.IsReady[client.Type] = false; } else if (client.Game.State == GameState.Side) { if (client.Game.IsReady[client.Type]) return; if (!client.Deck.Check(deck)) { using(GameServerPacket error = new GameServerPacket(StocMessage.ErrorMsg)){ error.Write((byte)3); error.Write(0); client.Send(error); } return; } client.Deck = deck; client.Game.IsReady[client.Type] = true; client.Game.ServerMessage(string.Format(Messages.MSG_READY, client.Name)); client.Send(GameServerPacket.EmtryMessage(StocMessage.DuelStart)); client.Game.MatchSide(); } }
public static void OnTpResult(GameSession client, GameClientPacket packet){ bool tp = packet.ReadByte() != 0; if(client.Game!=null) client.Game.TpResult(client, tp); }
public static void OnChat(GameSession client, GameClientPacket packet){ if (!client.IsAuthentified){ return; } string msg = packet.ReadUnicode(256); if(client.Game==null){ return; } if(!client.OnChatCommand(msg)){ using(GameServerPacket chat = new GameServerPacket(StocMessage.Chat)){ chat.Write((short)client.Type); chat.WriteUnicode(msg, msg.Length + 1); client.Game.SendToAllBut(chat, client); } } }
public static void OnTimeConfirm(GameSession client, GameClientPacket packet){ if(client!=null){ //Logger.Debug("OnTimeConfirm "+client.Name); } }
public void OnReceive(object obj) { if (m_close) return; //线程处理 bool next = true; while (next) { byte[] data; next = m_client.GetPacketData(GameServerPacket.GamePacketByteLength, out data); if (data!=null&& data.Length>0) { //处理游戏事件 GameClientPacket packet = new GameClientPacket(data); GameEvent.Handler(this, packet); } } }
public static void OnStartDuel(GameSession client, GameClientPacket packet){ if(client.Game!=null){ client.Game.StartDuel(client); } }
public static void OnLeaveGame(GameSession client, GameClientPacket packet){ client.CloseAsync(); }
public static void OnMoveToDeulList(GameSession client, GameClientPacket packet){ if (!client.IsAuthentified){ return; } if(client.Game!=null) client.Game.MoveToDuelist(client); }
public static void OnClose(GameSession client, GameClientPacket packet) { using (PacketWriter packet_write = new PacketWriter(GameServerPacket.GamePacketByteLength)) { packet_write.Write((byte)RoomMessage.STOP_CLIENT); client.Send(packet_write.Content); } client.CloseAsync(); }
private void InternalOnSelectCard(GameServerPacket packet, Func <IList <ClientCard>, int, int, bool, IList <ClientCard> > func) { packet.ReadByte(); // player bool cancelable = packet.ReadByte() != 0; int min = packet.ReadByte(); int max = packet.ReadByte(); IList <ClientCard> cards = new List <ClientCard>(); int count = packet.ReadByte(); for (int i = 0; i < count; ++i) { int id = packet.ReadInt32(); int player = GetLocalPlayer(packet.ReadByte()); CardLocation loc = (CardLocation)packet.ReadByte(); int seq = packet.ReadByte(); packet.ReadByte(); // pos ClientCard card; if (((int)loc & (int)CardLocation.Overlay) != 0) { card = new ClientCard(id, CardLocation.Overlay); } else { card = _duel.GetCard(player, loc, seq); } if (card == null) { continue; } if (card.Id == 0) { card.SetId(id); } cards.Add(card); } IList <ClientCard> selected = func(cards, min, max, cancelable); if (selected.Count == 0 && cancelable) { Connection.Send(CtosMessage.Response, -1); return; } byte[] result = new byte[selected.Count + 1]; result[0] = (byte)selected.Count; for (int i = 0; i < selected.Count; ++i) { int id = 0; for (int j = 0; j < count; ++j) { if (cards[j] == null) { continue; } if (cards[j].Equals(selected[i])) { id = j; break; } } result[i + 1] = (byte)id; } GameClientPacket reply = new GameClientPacket(CtosMessage.Response); reply.Write(result); Connection.Send(reply); }
public bool OnCheck() { byte[] data; if(m_client.GetPacketData(GameServerPacket.GamePacketByteLength, out data)) { GameClientPacket packet = new GameClientPacket(data); if (GameEvent.Handler(this, packet) == CtosMessage.PlayerInfo) { return true; } } Logger.Debug("first msg isn't PlayerInfo"); CloseAsync(); return false; }
public static void OnKick(GameSession client, GameClientPacket packet){ int pos = packet.ReadByte(); if(client.Game!=null) client.Game.KickPlayer(client, pos); }
public static void OnCreateGame(GameSession client, GameClientPacket packet){ if (string.IsNullOrEmpty(client.Name) || client.Type != (int)PlayerType.Undefined) return; GameRoom room = null; byte[] data = packet.ReadBytes(StructTransformer.SizeOf(typeof(CtosCreateGame))); CtosCreateGame roomconfig; GameConfig config = null; try { roomconfig = (CtosCreateGame)StructTransformer.BytesToStruct(data, typeof(CtosCreateGame)); config = roomconfig.Build(); } catch(Exception e) { Logger.Warn(e); } if (config == null) { client.CloseAsync(); return; } room = RoomManager.CreateOrGetGame(config); if (room == null) { client.LobbyError(Messages.MSG_FULL); return; } client.Game = room; lock (room.AsyncRoot) { room.AddPlayer(client); } //IsAuthentified = CheckAuth(); if(!client.IsAuthentified){ client.LobbyError(Messages.ERR_AUTH_FAIL); } }
public static void OnNotReady(GameSession client, GameClientPacket packet){ if (!client.IsAuthentified){ return; } if(client.Game!=null) client.Game.SetReady(client, false); }
private void OnSelectPlace(GameServerPacket packet) { packet.ReadByte(); // player packet.ReadByte(); // min int field = ~packet.ReadInt32(); byte[] resp = new byte[3]; bool pendulumZone = false; int filter; if ((field & 0x1f) != 0) { resp[0] = (byte)GetLocalPlayer(0); resp[1] = 0x4; filter = field & 0x1f; } else if ((field & 0x1f00) != 0) { resp[0] = (byte)GetLocalPlayer(0); resp[1] = 0x8; filter = (field >> 8) & 0x1f; } else if ((field & 0xc000) != 0) { resp[0] = (byte)GetLocalPlayer(0); resp[1] = 0x8; filter = (field >> 14) & 0x3; pendulumZone = true; } else if ((field & 0x1f0000) != 0) { resp[0] = (byte)GetLocalPlayer(1); resp[1] = 0x4; filter = (field >> 16) & 0x1f; } else if ((field & 0x1f000000) != 0) { resp[0] = (byte)GetLocalPlayer(1); resp[1] = 0x8; filter = (field >> 24) & 0x1f; } else { resp[0] = (byte)GetLocalPlayer(1); resp[1] = 0x8; filter = (field >> 30) & 0x3; pendulumZone = true; } if (!pendulumZone) { if ((filter & 0x4) != 0) { resp[2] = 2; } else if ((filter & 0x2) != 0) { resp[2] = 1; } else if ((filter & 0x8) != 0) { resp[2] = 3; } else if ((filter & 0x1) != 0) { resp[2] = 0; } else if ((filter & 0x10) != 0) { resp[2] = 4; } } else { if ((filter & 0x1) != 0) { resp[2] = 6; } if ((filter & 0x2) != 0) { resp[2] = 7; } } GameClientPacket reply = new GameClientPacket(CtosMessage.Response); reply.Write(resp); Connection.Send(reply); }
public static void OnMoveToObserver(GameSession client, GameClientPacket packet){ if (!client.IsAuthentified){ return; } if(client.Game!=null) client.Game.MoveToObserver(client); }
public static void OnPlayerInfo(GameSession client, GameClientPacket packet){ if (client.Name != null) return; string name = packet.ReadUnicode(20); Logger.Debug("player name:"+name); if(name == "client"){ client.LobbyError("[err]404"); return; } if (string.IsNullOrEmpty(name)){ client.LobbyError(Messages.ERR_NO_NAME); } client.Name = name; client.IsAuthentified = client.CheckAuth(name); }
// Methods public GCPacket(byte[] data) : base(data, Origin.GameClient) { this.PacketID = (GameClientPacket) data[0]; }
public static void OnJoinGame(GameSession client, GameClientPacket packet){ if (string.IsNullOrEmpty(client.Name) || client.Type != (int)PlayerType.Undefined){ Logger.Debug("join room fail:"+client.Name); return; } int version = packet.ReadInt16(); if (version < Program.Config.ClientVersion) { client.LobbyError(Messages.ERR_LOW_VERSION); return; } else if (version > Program.Config.ClientVersion){ client.ServerMessage(Messages.MSG_HIGH_VERSION); } int gameid = packet.ReadInt32();//gameid packet.ReadInt16(); string joinCommand = packet.ReadUnicode(60); GameRoom room = null; //IsAuthentified = CheckAuth(); if(!client.IsAuthentified){ client.LobbyError(Messages.ERR_AUTH_FAIL); return; } if(!RoomManager.CheckRoomPassword(joinCommand)){ client.LobbyError(Messages.ERR_PASSWORD); return; } GameConfig config = GameConfigBuilder.Build(joinCommand); room = RoomManager.CreateOrGetGame(config); if (room == null){ client.LobbyError(Messages.MSG_FULL); return; } if (!room.IsOpen) { client.LobbyError(Messages.MSG_GAMEOVER); return; } if(room!=null && room.Config!=null){ if(room.Config.NoCheckDeck){ client.ServerMessage(Messages.MSG_NOCHECKDECK); } if(room.Config.NoShuffleDeck){ client.ServerMessage(Messages.MSG_NOSHUFFLEDECK); } if(room.Config.EnablePriority){ client.ServerMessage(Messages.MSG_ENABLE_PROIORITY); } } client.Game = room; lock (room.AsyncRoot) { room.AddPlayer(client); } }