BattleClientDirect.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using CommonNetwork.Sockets;
  5. using CommonLang.Protocol;
  6. using RoomService.Net.BsServer;
  7. using CommonLang.Log;
  8. using RoomService.Net.BsClient;
  9. using CommonAI.ZoneClient;
  10. using CommonAI.Zone;
  11. using CommonLang.IO;
  12. using CommonAI.Zone.ZoneEditor;
  13. using CommonAI.ZoneServer;
  14. using CommonLang.Concurrent;
  15. using CommonNetwork.Net;
  16. using CommonLang.Property;
  17. using CommonAIClient;
  18. using CommonAI;
  19. namespace CommonAIClient.Client
  20. {
  21. public class BattleClientDirect : BattleClient, INetSessionListener
  22. {
  23. private static Logger log = LoggerFactory.GetLogger("BattleClientDirect");
  24. private INetSession session;
  25. public override INetSession Session { get { return session; } }
  26. public BattleClientDirect(
  27. EditorTemplates data_root,
  28. MessageFactoryGenerator msgFactory,
  29. PlayerWillConnectResponseB2R room,
  30. PlayerWillConnectRequestR2B testToken,
  31. string token)
  32. : base(data_root, msgFactory, room, testToken, token)
  33. {
  34. INetSession netSession = ReflectionUtil.CreateInterface<INetSession>(room.Room.NetDriverString);
  35. if (netSession == null)
  36. {
  37. throw new Exception("Invalid NetDriver : " + room.Room.NetDriverString);
  38. }
  39. this.session = netSession;
  40. }
  41. protected override void Disposing()
  42. {
  43. this.Stop();
  44. base.Disposing();
  45. }
  46. public override void Start()
  47. {
  48. session.Open(room.Room.ClientConnectString, new SynchronizedBattleCodec(base.DataRoot.Templates), this);
  49. }
  50. public override void Stop()
  51. {
  52. session.Close();
  53. }
  54. //----------------------------------------------------------------------------------------------------
  55. void INetSessionListener.sessionOpened(INetSession session)
  56. {
  57. base.callback_sessionOpened(session);
  58. }
  59. void INetSessionListener.sessionClosed(INetSession session)
  60. {
  61. base.callback_sessionClosed(session);
  62. }
  63. void INetSessionListener.messageReceived(INetSession session, object data)
  64. {
  65. base.callback_messageReceived(session, data);
  66. }
  67. void INetSessionListener.messageSent(INetSession session, object data)
  68. {
  69. base.callback_messageSent(session, data);
  70. }
  71. void INetSessionListener.onError(INetSession session, Exception err)
  72. {
  73. base.callback_onError(session, err);
  74. }
  75. }
  76. }