Пример #1
0
 public static bool CreateLobby(string Name)
 {
     if (MultiPlayer.Type("Game") == null)
     {
         Players = new Player[10];
         Self = Player.Add(new Player(Name));
         MultiPlayer.Start("Game", 6121, Players.Length);
         Timers.Add("Positions", (1 / 30d));
         return true;
     }
     else return false;
 }
Пример #2
0
 public static void Read(Packets Packet, NetIncomingMessage I)
 {
     switch (Packet)
     {
         case Packets.Connection:
             if (MultiPlayer.Type("Game") == MultiPlayer.Types.Server)
             {
                 ulong ClientVersion = I.ReadUInt64();
                 if (ClientVersion == Globe.Version)
                 {
                     Player Connector = Player.Add(new Player(I.ReadString()) { Connection = I.SenderConnection });
                     if (Connector != null)
                     {
                         MultiPlayer.Send("Game", MultiPlayer.Construct("Game", Packet, Connector.Slot, Connector.Name), I.SenderConnection);
                         List<object> Details = new List<object>();
                         for (byte i = 0; i < Players.Length; i++)
                             if ((Players[i] != null) && (Players[i] != Connector))
                             {
                                 Details.Add(true);
                                 Details.Add(Players[i].Name);
                             }
                             else Details.Add(false);
                         I.SenderConnection.Approve(MultiPlayer.Construct("Game", Packets.Initial, (byte)Players.Length, Connector.Slot, Details));
                     }
                     else I.SenderConnection.Deny("Full");
                 }
                 else I.SenderConnection.Deny("Version indifference, Client: " + ClientVersion + " - Server: " + Globe.Version);
             }
             else if (MultiPlayer.Type("Game") == MultiPlayer.Types.Client) { byte Slot = I.ReadByte(); Player.Set(Slot, new Player(I.ReadString())); }
             break;
         case Packets.Disconnection:
             Player Disconnector = ((MultiPlayer.Type("Game") == MultiPlayer.Types.Server) ? Player.Get(I.SenderConnection) :
                 ((MultiPlayer.Type("Game") == MultiPlayer.Types.Client) ? Players[I.ReadByte()] : null));
             if (Disconnector != null) Player.Remove(Disconnector);
             if (MultiPlayer.Type("Game") == MultiPlayer.Types.Server) MultiPlayer.Send("Game", MultiPlayer.Construct("Game", Packets.Disconnection, Disconnector.Slot), I.SenderConnection);
             break;
         case Packets.Initial:
             if (MultiPlayer.Type("Game") == MultiPlayer.Types.Client)
             {
                 Players = new Player[I.ReadByte()];
                 Self = Player.Set(I.ReadByte(), new Player(MpName) { });
                 for (byte i = 0; i < Players.Length; i++)
                     if (I.ReadBoolean())
                     {
                         Players[i] = new Player(i, I.ReadString());
                     }
                 Timers.Add("Positions", (1 / 30d));
                 State = States.Game;
             }
             break;
         case Packets.Position:
             Player Sender = ((MultiPlayer.Type("Game") == MultiPlayer.Types.Server) ? Player.Get(I.SenderConnection) : null);
             Vector2 Position; float Angle;
             if (MultiPlayer.Type("Game") == MultiPlayer.Types.Server)
             {
                 if (Sender != null)
                 {
                     Sender.Position = I.ReadVector2();
                     Sender.Angle = I.ReadFloat();
                 }
             }
             else if (MultiPlayer.Type("Game") == MultiPlayer.Types.Client)
             {
                 byte Count = (byte)((I.LengthBytes - 1) / 12);
                 for (byte i = 0; i < Count; i++)
                 {
                     Sender = Players[I.ReadByte()];
                     Position = I.ReadVector2();
                     Angle = I.ReadFloat();
                     if (Sender != null)
                     {
                         Sender.Position = Position;
                         Sender.Angle = Angle;
                     }
                 }
             }
             break;
     }
 }
Пример #3
0
 public static Player Set(byte Slot, Player P) { if (Slot < Players.Length) { P.Slot = Slot; Players[Slot] = P; return P; } return null; }
Пример #4
0
 public static bool Remove(Player P) { for (byte i = 0; i < Players.Length; i++) if (Players[i] == P) { Players[i] = null; return true; } return false; }
Пример #5
0
 public static Player Add(Player P) { for (byte i = 0; i < Players.Length; i++) if (Players[i] == null) { P.Slot = i; Players[i] = P; return P; } return null; }