| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- using System;
- using System.ComponentModel.Composition;
- using System.Windows.Threading;
- using ENet;
- using Microsoft.Practices.Prism.ViewModel;
- using Robot;
- namespace Modules.Robot
- {
- [Export(contractType: typeof (RobotViewModel)), PartCreationPolicy(creationPolicy: CreationPolicy.NonShared)]
- internal sealed class RobotViewModel: NotificationObject, IDisposable
- {
- private readonly ClientHost clientHost;
- private string loginIp;
- private ushort loginPort;
- private readonly DispatcherTimer timer = new DispatcherTimer(DispatcherPriority.Normal)
- { Interval = new TimeSpan(0, 0, 0, 0, 50) };
- public string LoginIp
- {
- get
- {
- return this.loginIp;
- }
- set
- {
- if (this.loginIp == value)
- {
- return;
- }
- this.loginIp = value;
- this.RaisePropertyChanged("LoginIp");
- }
- }
- public ushort LoginPort
- {
- get
- {
- return this.loginPort;
- }
- set
- {
- if (this.loginPort == value)
- {
- return;
- }
- this.loginPort = value;
- this.RaisePropertyChanged("LoginPort");
- }
- }
- public RobotViewModel()
- {
- this.clientHost = new ClientHost();
- this.timer.Tick += delegate { this.clientHost.RunOnce(); };
- this.timer.Start();
- }
- ~RobotViewModel()
- {
- this.Disposing(false);
- }
- public void Dispose()
- {
- this.Disposing(true);
- GC.SuppressFinalize(this);
- }
- private void Disposing(bool disposing)
- {
- this.clientHost.Dispose();
- }
- public void Login(string account, string password)
- {
- //try
- //{
- // var address = new Address { HostName = this.LoginIp, Port = this.LoginPort };
- // Peer peer = await this.clientHost.ConnectAsync(address);
- // using (Packet packet = await peer.ReceiveAsync())
- // {
- // var bytes = packet.Bytes;
- // var packetStream = new MemoryStream(bytes, 4, bytes.Length - 4);
- // var smsg = Serializer.Deserialize<SMSG_Auth_Challenge>(packetStream);
- // Logger.Debug(string.Format("opcode: {0}\n{1}",
- // BitConverter.ToUInt16(bytes, 0), XmlHelper.XmlSerialize(smsg)));
- // await peer.DisconnectLaterAsync();
- // }
- //}
- //catch (Exception e)
- //{
- // Logger.Debug(e.Message);
- //}
- var session = new RealmSession("192.168.11.95", 8888);
- session.Login(account, password);
- }
- }
- }
|