Advertisement
Guest User

Untitled

a guest
Feb 13th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1.  
  2. public static void SendDataTo(int index, byte[] data)
  3. {
  4. byte[] sizeinfo = new byte[4];
  5. sizeinfo[0] = (byte)data.Length;
  6. sizeinfo[1] = (byte)(data.Length >> 8);
  7. sizeinfo[2] = (byte)(data.Length >> 16);
  8. sizeinfo[3] = (byte)(data.Length >> 24);
  9.  
  10. Globals._clients[index].Slot.Send(sizeinfo);
  11. Globals._clients[index].Slot.Send(data);
  12.  
  13. //Console.WriteLine("Sending a packet to {0}, Index ({1})", Globals._clients[index].ip, Globals._clients[index].index);
  14.  
  15. }
  16.  
  17. public async void SendDataToAll(byte[] data)
  18. {
  19. for (int i = 1; i < Constants.MAX_PLAYERS; i++)
  20. {
  21. if (Globals._clients[i].Slot != null)
  22. {
  23. await Task.Delay(90);
  24. SendDataTo(i, data);
  25. }
  26. }
  27. }
  28.  
  29. public void SendDataToAllBut(int exceptionIndex, byte[] data)
  30. {
  31. for (int i = 1; i < Constants.MAX_PLAYERS; i++)
  32. {
  33. if (Globals._clients[i].Slot != null)
  34. {
  35. if (Globals._clients[i].index != exceptionIndex)
  36. {
  37. SendDataTo(i, data);
  38. }
  39. }
  40. }
  41. }
  42.  
  43.  
  44. public async void SendInGame(int index)
  45. {
  46. //Send Data To Player
  47. SendDataTo(index, PlayerData(index));
  48. // Send all players to the player himself
  49. for (int i = 1; i < Constants.MAX_PLAYERS; i++)
  50. {
  51. if (Globals.general.IsPlaying(i))
  52. {
  53. if (Globals._clients[i].index != index)
  54. {
  55. await Task.Delay(75);
  56. SendDataTo(index, PlayerData(i));
  57. LoadPlayers(index); // Exception Index;
  58. }
  59.  
  60. }
  61. }
  62.  
  63. Console.WriteLine("JOINED IN GAME: " + Globals.player[index].Username);
  64. }
  65.  
  66.  
  67. public async void LoadPlayers(int index)
  68. {
  69. for (int i = 1; i < Globals._clients.Length; i++)
  70. {
  71. if (Globals.general.IsPlaying(i))
  72. {
  73. if (Globals._clients[i].index != index)
  74. {
  75. await Task.Delay(75);
  76. SendDataTo(i, PlayerData(index));
  77. Console.WriteLine("Load Players" + index);
  78.  
  79. }
  80.  
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement