Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void SendDataTo(int index, byte[] data)
- {
- byte[] sizeinfo = new byte[4];
- sizeinfo[0] = (byte)data.Length;
- sizeinfo[1] = (byte)(data.Length >> 8);
- sizeinfo[2] = (byte)(data.Length >> 16);
- sizeinfo[3] = (byte)(data.Length >> 24);
- Globals._clients[index].Slot.Send(sizeinfo);
- Globals._clients[index].Slot.Send(data);
- //Console.WriteLine("Sending a packet to {0}, Index ({1})", Globals._clients[index].ip, Globals._clients[index].index);
- }
- public async void SendDataToAll(byte[] data)
- {
- for (int i = 1; i < Constants.MAX_PLAYERS; i++)
- {
- if (Globals._clients[i].Slot != null)
- {
- await Task.Delay(90);
- SendDataTo(i, data);
- }
- }
- }
- public void SendDataToAllBut(int exceptionIndex, byte[] data)
- {
- for (int i = 1; i < Constants.MAX_PLAYERS; i++)
- {
- if (Globals._clients[i].Slot != null)
- {
- if (Globals._clients[i].index != exceptionIndex)
- {
- SendDataTo(i, data);
- }
- }
- }
- }
- public async void SendInGame(int index)
- {
- //Send Data To Player
- SendDataTo(index, PlayerData(index));
- // Send all players to the player himself
- for (int i = 1; i < Constants.MAX_PLAYERS; i++)
- {
- if (Globals.general.IsPlaying(i))
- {
- if (Globals._clients[i].index != index)
- {
- await Task.Delay(75);
- SendDataTo(index, PlayerData(i));
- LoadPlayers(index); // Exception Index;
- }
- }
- }
- Console.WriteLine("JOINED IN GAME: " + Globals.player[index].Username);
- }
- public async void LoadPlayers(int index)
- {
- for (int i = 1; i < Globals._clients.Length; i++)
- {
- if (Globals.general.IsPlaying(i))
- {
- if (Globals._clients[i].index != index)
- {
- await Task.Delay(75);
- SendDataTo(i, PlayerData(index));
- Console.WriteLine("Load Players" + index);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement