BaseRoom.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Sfs2X.Entities.Data;
  5. public class BaseRoom : BARoom
  6. {
  7. public BaseRoom(BAServer server) : base(server)
  8. {
  9. m_MaxUsers = 100;
  10. isRecord = false;
  11. }
  12. protected override void CheckGameStart ()
  13. {
  14. }
  15. protected override void CheckAITaker ()
  16. {
  17. }
  18. public void InitBaseUsers()
  19. {
  20. InviteManager.GetInstance ().ActionUpdate.RemoveListener (OnActionUpdate);
  21. InviteManager.GetInstance ().StateUpdate.RemoveListener (OnStateUpdate);
  22. InviteManager.GetInstance ().ActionUpdate.AddListener (OnActionUpdate);
  23. InviteManager.GetInstance ().StateUpdate.AddListener (OnStateUpdate);
  24. ISFSArray arr = new SFSArray ();
  25. List<InviteData> list = InviteManager.GetInstance ().GetDataList ();
  26. for(int i=0; i<list.Count; i++)
  27. {
  28. InviteData inviteData = list [i];
  29. if (inviteData.state != InviteData.State.Online)
  30. continue;
  31. ISFSObject obj = Invite2PlayerData(inviteData);
  32. arr.AddSFSObject (obj);
  33. }
  34. SendPlayerJoin(arr);
  35. }
  36. private ISFSObject Invite2PlayerData(InviteData inviteData)
  37. {
  38. ISFSObject obj = new SFSObject ();
  39. obj.PutUtfString (UserSFSObjectLabel.ID, inviteData.id.ToString ());
  40. obj.PutUtfString (UserSFSObjectLabel.NICK, UserCache.GetNick(inviteData.id));
  41. obj.PutInt (UserSFSObjectLabel.TEAM_ID, TeamUtil.Team.Blue.GetHashCode ());
  42. obj.PutInt (UserSFSObjectLabel.PLAYER_ID, inviteData.id);
  43. return obj;
  44. }
  45. private void SendPlayerJoin(ISFSArray arr)
  46. {
  47. ISFSObject obj = new SFSObject ();
  48. obj.PutSFSArray ("a", arr);
  49. Message message = new Message (Command.PlayerJoin, obj);
  50. server.RoomHandleResponse (message.GetMessagePackage ());
  51. }
  52. private void SendPlayerLeft(int id)
  53. {
  54. ISFSObject obj = new SFSObject ();
  55. obj.PutUtfString ("u", id.ToString());
  56. Message message = new Message (Command.PlayerLeft, obj);
  57. server.RoomHandleResponse (message.GetMessagePackage ());
  58. }
  59. private void OnActionUpdate(int id)
  60. {
  61. }
  62. private void OnStateUpdate(int id)
  63. {
  64. InviteData inviteData = InviteManager.GetInstance ().GetData (id);
  65. if (inviteData == null)
  66. return;
  67. if (inviteData.state == InviteData.State.Online) {
  68. ISFSObject obj = Invite2PlayerData (inviteData);
  69. ISFSArray arr = new SFSArray ();
  70. arr.AddSFSObject(obj);
  71. SendPlayerJoin (arr);
  72. }
  73. }
  74. public override void Dispose ()
  75. {
  76. InviteManager.GetInstance ().ActionUpdate.RemoveListener (OnActionUpdate);
  77. InviteManager.GetInstance ().StateUpdate.RemoveListener (OnStateUpdate);
  78. }
  79. }