public static Create ( GameMessage message ) : BinaryWriter | ||
message | GameMessage | |
Результат | BinaryWriter |
private void SendJoinGame(Player player) { BinaryWriter join = GamePacketFactory.Create(StocMessage.JoinGame); join.Write(Banlist == null ? 0U : Banlist.Hash); join.Write((byte)Region); join.Write((byte)Mode); join.Write((byte)MasterRule); join.Write(NoCheckDeck); join.Write(NoShuffleDeck); // C++ padding: 5 bytes + 3 bytes = 8 bytes for (int i = 0; i < 3; i++) { join.Write((byte)0); } join.Write(StartLp); join.Write((byte)StartHand); join.Write((byte)DrawCount); join.Write((short)Timer); player.Send(join); if (State != GameState.Lobby) { SendDuelingPlayers(player); } }
private void OnDraw(CoreMessage msg) { GamePacketWriter packet = GamePacketFactory.Create(msg.Message); int player = msg.Reader.ReadByte(); int count = msg.Reader.ReadByte(); packet.Write((byte)player); packet.Write((byte)count); for (int i = 0; i < count; i++) { uint code = msg.Reader.ReadUInt32(); if ((code & 0x80000000) != 0) { packet.Write(code); } else { packet.Write(0); } } SendToPlayer(msg, player); Game.SendToAllBut(packet, player); }
private void OnMove(CoreMessage msg) { byte[] raw = msg.Reader.ReadBytes(16); int pc = raw[4]; int pl = raw[5]; int cc = raw[8]; int cl = raw[9]; int cs = raw[10]; int cp = raw[11]; SendToPlayer(msg, cc); GamePacketWriter packet = GamePacketFactory.Create(msg.Message); packet.Write(raw); if (!Convert.ToBoolean((cl & ((int)CardLocation.Grave + (int)CardLocation.Overlay))) && Convert.ToBoolean((cl & ((int)CardLocation.Deck + (int)CardLocation.Hand))) || Convert.ToBoolean((cp & (int)CardPosition.FaceDown))) { packet.SetPosition(2); packet.Write(0); } Game.SendToAllBut(packet, cc); if (cl != 0 && (cl & 0x80) == 0 && (cl != pl || pc != cc)) { Game.RefreshSingle(cc, cl, cs); } }
private void InitNewSpectator(Player player) { BinaryWriter packet = GamePacketFactory.Create(GameMessage.Start); packet.Write((byte)0x10); packet.Write((byte)MasterRule); packet.Write(LifePoints[0]); packet.Write(LifePoints[1]); packet.Write((short)0); // deck packet.Write((short)0); // extra packet.Write((short)0); // deck packet.Write((short)0); // extra player.Send(packet); BinaryWriter turn = GamePacketFactory.Create(GameMessage.NewTurn); turn.Write((byte)0); player.Send(turn); if (CurrentPlayer == 1) { turn = GamePacketFactory.Create(GameMessage.NewTurn); turn.Write((byte)0); player.Send(turn); } BinaryWriter reload = GamePacketFactory.Create(GameMessage.ReloadField); byte[] fieldInfo = _duel.QueryFieldInfo(); reload.Write(fieldInfo, 1, fieldInfo.Length - 1); player.Send(reload); RefreshAllObserver(player); }
public void MoveToObserver(Player player) { if (State != GameState.Lobby) { return; } if (player.Type == (int)PlayerType.Observer) { return; } if (IsReady[player.Type]) { return; } int oldType = player.Type; Players[player.Type] = null; IsReady[player.Type] = false; Observers.Add(player); BinaryWriter change = GamePacketFactory.Create(StocMessage.HsPlayerChange); change.Write((byte)((player.Type << 4) + (int)PlayerChange.Observe)); SendToAll(change); player.Type = (int)PlayerType.Observer; player.SendTypeChange(); if (OnPlayerMove != null) { OnPlayerMove(this, new PlayerMoveEventArgs(player, oldType)); } }
private void OnSelectCard(CoreMessage msg) { GamePacketWriter packet = GamePacketFactory.Create(msg.Message); int player = msg.Reader.ReadByte(); packet.Write((byte)player); packet.Write(msg.Reader.ReadBytes(3)); int count = msg.Reader.ReadByte(); packet.Write((byte)count); for (int i = 0; i < count; i++) { int code = msg.Reader.ReadInt32(); int pl = msg.Reader.ReadByte(); int loc = msg.Reader.ReadByte(); int seq = msg.Reader.ReadByte(); int pos = msg.Reader.ReadByte(); packet.Write(pl == player ? code : 0); packet.Write((byte)pl); packet.Write((byte)loc); packet.Write((byte)seq); packet.Write((byte)pos); } Game.WaitForResponse(player); Game.CurPlayers[player].Send(packet); }
public void StartDuel(Player player) { if (State != GameState.Lobby) { return; } if (!player.Equals(HostPlayer)) { return; } for (int i = 0; i < Players.Length; i++) { if (!IsReady[i]) { return; } if (Players[i] == null) { return; } } State = GameState.Hand; SendToAll(GamePacketFactory.Create(StocMessage.DuelStart)); SendHand(); if (OnGameStart != null) { OnGameStart(this, EventArgs.Empty); } }
public void SendTypeChange() { BinaryWriter packet = GamePacketFactory.Create(StocMessage.TypeChange); packet.Write((byte)((IsRecorder ? (int)PlayerType.Observer : Type) + (Game.HostPlayer.Equals(this) ? (int)PlayerType.Host : 0))); Send(packet); }
private void OnDraw(CoreMessage msg) { BinaryWriter packet = GamePacketFactory.Create(msg.Message); int player = msg.Reader.ReadByte(); int count = msg.Reader.ReadByte(); packet.Write((byte)player); packet.Write((byte)count); for (int i = 0; i < count; i++) { uint code = msg.Reader.ReadUInt32(); if ((code & 0x80000000) != 0) { packet.Write(code); } else { packet.Write(0); } } SendToTeam(msg, player); SendToOpponentTeam(packet, player); Game.SendToObservers(packet); }
public void Surrender(Player player, int reason, bool force = false) { if (State == GameState.End) { return; } if (!force && State != GameState.Duel) { return; } if (player.Type == (int)PlayerType.Observer) { return; } BinaryWriter win = GamePacketFactory.Create(GameMessage.Win); int team = player.Type; if (IsTag) { team = player.Type >= 2 ? 1 : 0; } else if (State == GameState.Hand) { team = 1 - team; } win.Write((byte)(1 - team)); win.Write((byte)reason); SendToAll(win); MatchSaveResult(1 - team, reason); EndDuel(reason == 4); }
private void SendToCorrectDestination(int player, CardLocation location, byte[] result, Player observer) { BinaryWriter update; if (observer == null) { update = GamePacketFactory.Create(GameMessage.UpdateData); update.Write((byte)player); update.Write((byte)location); update.Write(result); SendToTeam(update, player); } update = GamePacketFactory.Create(GameMessage.UpdateData); update.Write((byte)player); update.Write((byte)location); WritePublicCards(update, result); if (observer == null) { SendToTeam(update, 1 - player); SendToObservers(update); } else { observer.Send(update); } }
public void RemovePlayer(Player player) { if (player.Equals(HostPlayer) && State == GameState.Lobby) { bool found = false; foreach (Player p in Players) { if (p != null && !p.Equals(player)) { HostPlayer = p; found = true; break; } } if (found) { IsReady[HostPlayer.Type] = false; HostPlayer.SendTypeChange(); } else { _server.Stop(); return; } } if (player.IsRecorder) { player.Disconnect(); } if (player.Type == (int)PlayerType.Observer) { Observers.Remove(player); if (State == GameState.Lobby) { BinaryWriter nwatch = GamePacketFactory.Create(StocMessage.HsWatchChange); nwatch.Write((short)Observers.Count); SendToAll(nwatch); } player.Disconnect(); } else if (State == GameState.Lobby) { Players[player.Type] = null; IsReady[player.Type] = false; BinaryWriter change = GamePacketFactory.Create(StocMessage.HsPlayerChange); change.Write((byte)((player.Type << 4) + (int)PlayerChange.Leave)); SendToAll(change); player.Disconnect(); } else { Surrender(player, 4, true); } if (OnPlayerLeave != null) { OnPlayerLeave(this, new PlayerEventArgs(player)); } }
private void SendToAll(CoreMessage msg) { byte[] buffer = msg.CreateBuffer(); GamePacketWriter packet = GamePacketFactory.Create(msg.Message); packet.Write(buffer); Game.SendToAll(packet); }
private void OnRetry() { int player = Game.WaitForResponse(); Game.CurPlayers[player].Send(GamePacketFactory.Create(GameMessage.Retry)); Game.Replay.End(); }
private void SendToReplayRecorder(CoreMessage msg) { byte[] buffer = msg.CreateBuffer(); BinaryWriter packet = GamePacketFactory.Create(msg.Message); packet.Write(buffer); Game.SendToReplayRecorder(packet); }
private void OnRetry() { int player = Game.WaitForResponse(); Game.CurPlayers[player].Send(GamePacketFactory.Create(GameMessage.Retry)); Game.Replay.End(); //File.WriteAllBytes("error_" + DateTime.UtcNow.ToString("yyyy-MM-dd_HH-mm-ss") + ".yrp", Game.Replay.GetFile()); }
public void CustomMessage(Player player, string msg) { string finalmsg = msg; BinaryWriter packet = GamePacketFactory.Create(StocMessage.Chat); packet.Write((short)PlayerType.Yellow); packet.WriteUnicode(finalmsg, finalmsg.Length + 1); SendToAllBut(packet, player); }
public void RefreshExtra(int player, int flag = 0x81fff) { byte[] result = _duel.QueryFieldCard(player, CardLocation.Extra, flag, false); GamePacketWriter update = GamePacketFactory.Create(GameMessage.UpdateData); update.Write((byte)player); update.Write((byte)CardLocation.Extra); update.Write(result); CurPlayers[player].Send(update); }
private void OnSet(CoreMessage msg) { msg.Reader.ReadBytes(4); byte[] raw = msg.Reader.ReadBytes(4); GamePacketWriter packet = GamePacketFactory.Create(GameMessage.Set); packet.Write(0); packet.Write(raw); Game.SendToAll(packet); }
private void HandleError(string error) { BinaryWriter packet = GamePacketFactory.Create(StocMessage.Chat); packet.Write((short)PlayerType.Observer); packet.WriteUnicode(error, error.Length + 1); SendToAll(packet); File.WriteAllText("lua_" + DateTime.UtcNow.ToString("yyyy-MM-dd_HH-mm-ss") + ".txt", error); }
private void SendToAll(CoreMessage msg, int length) { if (length == 0) { Game.SendToAll(GamePacketFactory.Create(msg.Message)); return; } msg.Reader.ReadBytes(length); SendToAll(msg); }
public void SetReady(Player player, bool ready) { if (State != GameState.Lobby) { return; } if (player.Type == (int)PlayerType.Observer) { return; } if (IsReady[player.Type] == ready) { return; } if (ready) { bool ocg = Region == 0 || Region == 2; bool tcg = Region == 1 || Region == 2; int result = 1; if (player.Deck != null) { result = NoCheckDeck ? 0 : player.Deck.Check(Banlist, ocg, tcg); } if (result != 0) { BinaryWriter rechange = GamePacketFactory.Create(StocMessage.HsPlayerChange); rechange.Write((byte)((player.Type << 4) + (int)(PlayerChange.NotReady))); player.Send(rechange); BinaryWriter error = GamePacketFactory.Create(StocMessage.ErrorMsg); error.Write((byte)2); // ErrorMsg.DeckError // C++ padding: 1 byte + 3 bytes = 4 bytes for (int i = 0; i < 3; i++) { error.Write((byte)0); } error.Write(result); player.Send(error); return; } } IsReady[player.Type] = ready; BinaryWriter change = GamePacketFactory.Create(StocMessage.HsPlayerChange); change.Write((byte)((player.Type << 4) + (int)(ready ? PlayerChange.Ready : PlayerChange.NotReady))); SendToAll(change); if (OnPlayerReady != null) { OnPlayerReady(this, new PlayerEventArgs(player)); } }
public void MatchSide() { if (IsReady[0] && IsReady[1]) { State = GameState.Starting; IsTpSelect = true; TpTimer = DateTime.UtcNow; TimeReset(); Players[_startplayer].Send(GamePacketFactory.Create(StocMessage.SelectTp)); } }
private void SendToTeam(CoreMessage msg, int player) { if (player != 0 && player != 1) { return; } byte[] buffer = msg.CreateBuffer(); BinaryWriter packet = GamePacketFactory.Create(msg.Message); packet.Write(buffer); Game.SendToTeam(packet, player); }
private void SendDuelingPlayers(Player player) { for (int i = 0; i < Players.Length; i++) { BinaryWriter enter = GamePacketFactory.Create(StocMessage.HsPlayerEnter); enter.WriteUnicode(Players[i].Name, 20); enter.Write((byte)i); //padding enter.Write((byte)0); player.Send(enter); } }
public void End() { State = GameState.End; SendToAll(GamePacketFactory.Create(StocMessage.DuelEnd)); _server.StopDelayed(); if (OnGameEnd != null) { OnGameEnd(this, EventArgs.Empty); } }
private void SendToPlayer(CoreMessage msg, int player) { if (player != 0 && player != 1) { return; } byte[] buffer = msg.CreateBuffer(); GamePacketWriter packet = GamePacketFactory.Create(msg.Message); packet.Write(buffer); Game.CurPlayers[player].Send(packet); }
private void OnTagSwap(CoreMessage msg) { BinaryWriter packet = GamePacketFactory.Create(GameMessage.TagSwap); int player = msg.Reader.ReadByte(); packet.Write((byte)player); packet.Write(msg.Reader.ReadByte()); // mcount int ecount = msg.Reader.ReadByte(); packet.Write((byte)ecount); packet.Write(msg.Reader.ReadByte()); // pcount int hcount = msg.Reader.ReadByte(); packet.Write((byte)hcount); packet.Write(msg.Reader.ReadBytes(4)); // topcode for (int i = 0; i < hcount + ecount; i++) { uint code = msg.Reader.ReadUInt32(); if ((code & 0x80000000) != 0) { packet.Write(code); } else { packet.Write(0); } } if (Game.CurPlayers[player].Equals(Game.Players[player * 2])) { Game.CurPlayers[player] = Game.Players[player * 2 + 1]; } else { Game.CurPlayers[player] = Game.Players[player * 2]; } SendToPlayer(msg, player); Game.SendToAllBut(packet, player); Game.RefreshExtra(player); Game.RefreshMonsters(0); Game.RefreshMonsters(1); Game.RefreshSpells(0); Game.RefreshSpells(1); Game.RefreshHand(0); Game.RefreshHand(1); }
public void RefreshSpells(int player, int flag = 0x681fff, Player observer = null) { byte[] result = _duel.QueryFieldCard(player, CardLocation.SpellZone, flag, false); GamePacketWriter update = GamePacketFactory.Create(GameMessage.UpdateData); update.Write((byte)player); update.Write((byte)CardLocation.SpellZone); update.Write(result); if (observer == null) { SendToTeam(update, player); } update = GamePacketFactory.Create(GameMessage.UpdateData); update.Write((byte)player); update.Write((byte)CardLocation.SpellZone); MemoryStream ms = new MemoryStream(result); BinaryReader reader = new BinaryReader(ms); for (int i = 0; i < 8; i++) { int len = reader.ReadInt32(); if (len == 4) { update.Write(4); continue; } byte[] raw = reader.ReadBytes(len - 4); if ((raw[11] & (int)CardPosition.FaceDown) != 0) { update.Write(8); update.Write(0); } else { update.Write(len); update.Write(raw); } } if (observer == null) { SendToTeam(update, 1 - player); SendToObservers(update); } else { observer.Send(update); } }
public void WaitForResponse(int player) { _lastresponse = player; CurPlayers[player].State = PlayerState.Response; SendToAllBut(GamePacketFactory.Create(GameMessage.Waiting), player); TimeStart(); BinaryWriter packet = GamePacketFactory.Create(StocMessage.TimeLimit); packet.Write((byte)player); packet.Write((byte)0); // C++ padding packet.Write((short)_timelimit[player]); SendToPlayers(packet); }