MatchMessages.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. namespace Mirror.Examples.MultipleMatch
  3. {
  4. /// <summary>
  5. /// Match message to be sent to the server
  6. /// </summary>
  7. public struct ServerMatchMessage : NetworkMessage
  8. {
  9. public ServerMatchOperation serverMatchOperation;
  10. public Guid matchId;
  11. }
  12. /// <summary>
  13. /// Match message to be sent to the client
  14. /// </summary>
  15. public struct ClientMatchMessage : NetworkMessage
  16. {
  17. public ClientMatchOperation clientMatchOperation;
  18. public Guid matchId;
  19. public MatchInfo[] matchInfos;
  20. public PlayerInfo[] playerInfos;
  21. }
  22. /// <summary>
  23. /// Information about a match
  24. /// </summary>
  25. [Serializable]
  26. public struct MatchInfo
  27. {
  28. public Guid matchId;
  29. public byte players;
  30. public byte maxPlayers;
  31. }
  32. /// <summary>
  33. /// Information about a player
  34. /// </summary>
  35. [Serializable]
  36. public struct PlayerInfo
  37. {
  38. public int playerIndex;
  39. public bool ready;
  40. public Guid matchId;
  41. }
  42. [Serializable]
  43. public struct MatchPlayerData
  44. {
  45. public int playerIndex;
  46. public int wins;
  47. public CellValue currentScore;
  48. }
  49. /// <summary>
  50. /// Match operation to execute on the server
  51. /// </summary>
  52. public enum ServerMatchOperation : byte
  53. {
  54. None,
  55. Create,
  56. Cancel,
  57. Start,
  58. Join,
  59. Leave,
  60. Ready
  61. }
  62. /// <summary>
  63. /// Match operation to execute on the client
  64. /// </summary>
  65. public enum ClientMatchOperation : byte
  66. {
  67. None,
  68. List,
  69. Created,
  70. Cancelled,
  71. Joined,
  72. Departed,
  73. UpdateRoom,
  74. Started
  75. }
  76. // A1 | B1 | C1
  77. // ---+----+---
  78. // A2 | B2 | C2
  79. // ---+----+---
  80. // A3 | B3 | C3
  81. [Flags]
  82. public enum CellValue : ushort
  83. {
  84. None,
  85. A1 = 1 << 0,
  86. B1 = 1 << 1,
  87. C1 = 1 << 2,
  88. A2 = 1 << 3,
  89. B2 = 1 << 4,
  90. C2 = 1 << 5,
  91. A3 = 1 << 6,
  92. B3 = 1 << 7,
  93. C3 = 1 << 8,
  94. // winning combinations
  95. TopRow = A1 + B1 + C1,
  96. MidRow = A2 + B2 + C2,
  97. BotRow = A3 + B3 + C3,
  98. LeftCol = A1 + A2 + A3,
  99. MidCol = B1 + B2 + B3,
  100. RightCol = C1 + C2 + C3,
  101. Diag1 = A1 + B2 + C3,
  102. Diag2 = A3 + B2 + C1,
  103. // board is full (winner / draw)
  104. Full = TopRow + MidRow + BotRow
  105. }
  106. }