Esempio n. 1
0
 protected override object ExecuteCommand(object par)
 {
     lock (Client.ConnectingLock)
     {
         if (CanExecuteCommand(par))
         {
             Client.ClientStatus = ClientStatus.ConnectPending;
             Client.CreateFactories();
             try
             {
                 CheckError(MainChannel.Connect(
                                new Connection
                 {
                     ClientType      = Client.Settings.ClientType,
                     ClientUniqueKey = Client.UniqueKey,
                     User            = Client.User,
                 }, out Client.Token));
             }
             catch (Exception ex)
             {
                 // unsubscribe is impossible due to MainChannel fault
                 Client.ClientStatus = ClientStatus.Refused;
                 Client.CloseFactories();
                 Client.OnConnectError(ex);
                 throw;
             }
             Client.ClientStatus = ClientStatus.Connected;
         }
     }
     return(null);
 }
Esempio n. 2
0
 protected override object ExecuteCommand(object par)
 {
     if (par is ChatUserStatus)
     {
         CheckError(MainChannel.ChangeStatus((ChatUserStatus)par));
     }
     return(null);
 }
Esempio n. 3
0
        private void DoReconnectAttempt()
        {
            ReconnectAttempt?.Invoke(this, EventArgs.Empty);

            MainChannel.AddMessage(new ChatMessage(null, Color.White, DateTime.Now, "Attempting to reconnect to CnCNet..."));

            connection.ConnectAsync();
        }
Esempio n. 4
0
 protected override object ExecuteCommand(object par)
 {
     if (par is User)
     {
         CheckError(MainChannel.StartChat((User)par));
     }
     return(null);
 }
Esempio n. 5
0
        public void UserEnter()
        {
            try
            {
                if (MainChannel == null)
                {
                    string ipe = String.Format("{0}:{1}", ServerIP, (int)PortID.MainService);
                    //string ipe = String.Format("localhost:{0}", (int)PortID.MainService);
                    InstanceContext inst    = new InstanceContext(MainForm.Instance);
                    var             binding = new NetTcpBinding(SecurityMode.None);
                    binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
                    binding.Security.Transport.ProtectionLevel      = System.Net.Security.ProtectionLevel.EncryptAndSign;
                    binding.MaxReceivedMessageSize = 1024 * 1024 * 1024;
                    binding.MaxBufferPoolSize      = 1024 * 1024 * 1024;
                    MainChannel = DuplexChannelFactory <IMainService> .CreateChannel(inst, binding, new EndpointAddress(string.Format("{0}://{1}/MainService", binding.Scheme, ipe)));

                    ((IContextChannel)MainChannel).OperationTimeout = new TimeSpan(0, 0, 10);
                    ((IContextChannel)MainChannel).Closed          += new EventHandler(ProxyMainService_Closed);
                    ((IContextChannel)MainChannel).Faulted         += new EventHandler(ProxyMainService_Faulted);
                }

                if (TransmissionChannel == null)
                {
                    var    binding = new NetTcpBinding(SecurityMode.None);
                    string addr    = String.Format("{0}://{1}:{2}/TransmissionRequestService", binding.Scheme, ServerIP, (int)PortID.DownloadTransmissionDetection);
                    TransmissionChannel = ChannelFactory <ITransmissionRequestService> .CreateChannel(binding, new EndpointAddress(addr));
                }
                // 启动心跳线程
                ThreadPool.QueueUserWorkItem(new WaitCallback(obj =>
                {
                    while (MainChannel != null && LoginChannel != null)
                    {
                        try
                        {
                            if (!MainChannel.BeatingHeart(Program.CurUser.Info.LinkPort))
                            {
                                throw new System.ServiceModel.ServiceActivationException();
                            }
                        }
                        catch
                        {
                            MainForm.Instance.InvokeEx(() => MainForm.Instance.ShowLoginForm());
                        }
#if DEBUG
                        break;
#else
                        Thread.Sleep(2000);
#endif
                    }
                }));
            }
            catch (Exception ex)
            {
                //LogSink.Write(MessageLevel.错误, MessageType.登录连接, "创建或连接服务失败:" + ex.Message);
            }
        }
Esempio n. 6
0
 protected override object ExecuteCommand(object message)
 {
     if (message is string)
     {
         CheckError(MainChannel.CreateRoom(new ChatRoom {
             Name = (string)message
         }));
     }
     if (message is ChatRoom)
     {
         CheckError(MainChannel.CreateRoom((ChatRoom)message));
     }
     return(null);
 }
Esempio n. 7
0
        public async Task Open()
        {
            // open socket
            //TODO: proper disposable handling
            var socket = await Connect();

            var sChannel = new MainChannel(socket);

            _channels.Add(0, (IChannel)sChannel);

            var comms = ProcessLinesAsync(socket, _channels);

            sChannel.KickOff();
            await comms;
        }
Esempio n. 8
0
 public void Logout(bool requestServer)
 {
     Program.CurUser.Info = null;
     ProjectDoc.Instance.CurEditUserID = 0;
     try
     {
         if (requestServer && MainChannel != null)
         {
             MainChannel.Logout();
         }
     }
     catch { }
     finally
     {
         Disconnect();
     }
 }
Esempio n. 9
0
        protected override object ExecuteCommand(object message)
        {
            string method;

            object[] pars;
            if (message is string)
            {
                // example ListEntities=int:12;string:a
                var s = ((string)message).Split('=');
                method = s[0];
                var l = new List <object>();
                foreach (var p in s[1].Split(';'))
                {
                    var    ss = p.Split(':');
                    object o;
                    switch (ss[0])
                    {
                    case "int":
                        o = int.Parse(ss[1]);
                        break;

                    default:
                        o = ss[1];
                        break;
                    }
                    l.Add(o);
                }
                pars = l.ToArray();
            }
            else
            {
                var pair = (KeyValuePair <string, object[]>)message;
                method = pair.Key;
                pars   = pair.Value;
            }
            var r = MainChannel.GetType().GetMethod(method).Invoke(MainChannel, pars);

            if (SourceControl is ContentControl)
            {
                var cc = (ContentControl)SourceControl;
                cc.Dispatcher.Invoke(DispatcherPriority.Normal,
                                     (Action) delegate { cc.Content = r; });
            }
            return(r);
        }
Esempio n. 10
0
        protected override object ExecuteCommand(object message)
        {
            KeyValuePair <string, object> pair;

            if (message is KeyValuePair <string, object> )
            {
                pair = (KeyValuePair <string, object>)message;
            }
            else
            {
                pair = new KeyValuePair <string, object>(null, null);
            }

            object remark = null;
            List <ConfigurationSetting> list = MainChannel.ServerSettings(pair.Key, pair.Value, ref remark);

            return(new KeyValuePair <List <ConfigurationSetting>, object>(list, remark));
        }
Esempio n. 11
0
        private void DoConnectionLost(string reason)
        {
            ConnectionLost?.Invoke(this, new ConnectionLostEventArgs(reason));

            for (int i = 0; i < channels.Count; i++)
            {
                if (!channels[i].Persistent)
                {
                    channels.RemoveAt(i);
                    i--;
                }
                else
                {
                    channels[i].ClearUsers();
                }
            }

            MainChannel.AddMessage(new ChatMessage(null, Color.Red, DateTime.Now, "Connection to CnCNet has been lost."));
            connected = false;
        }
Esempio n. 12
0
        private void DoDisconnected()
        {
            for (int i = 0; i < channels.Count; i++)
            {
                if (!channels[i].Persistent)
                {
                    channels.RemoveAt(i);
                    i--;
                }
                else
                {
                    channels[i].ClearUsers();
                }
            }

            MainChannel.AddMessage(new ChatMessage(null, Color.White, DateTime.Now, "You have disconnected from CnCNet."));
            connected = false;

            Disconnected?.Invoke(this, EventArgs.Empty);
        }
Esempio n. 13
0
        private void DoChannelFull(string channelName)
        {
            ChannelFull?.Invoke(this, new ChannelEventArgs(channelName));

            int    gameIndex = hostedGames.FindIndex(c => c.ChannelName == channelName);
            string gameName  = null;

            if (gameIndex > -1)
            {
                gameName = hostedGames[gameIndex].ChannelName;
            }

            string message;

            message = string.IsNullOrEmpty(gameName) ?
                      "The selected game is full! " + channelName :
                      string.Format("Cannot join game {0}; it is full!", gameName);

            MainChannel.AddMessage(new ChatMessage(null, Color.White, DateTime.Now,
                                                   message));
        }
Esempio n. 14
0
        /// <summary>
        /// Handles situations when the requested name is already in use by another
        /// IRC user. Adds additional underscores to the name or replaces existing
        /// characters with underscores.
        /// </summary>
        private void DoNameAlreadyInUse()
        {
            var charList      = ProgramConstants.PLAYERNAME.ToList();
            int maxNameLength = ClientConfiguration.Instance.MaxNameLength;

            if (charList.Count < maxNameLength)
            {
                charList.Add('_');
            }
            else
            {
                int lastNonUnderscoreIndex = charList.FindLastIndex(c => c != '_');

                if (lastNonUnderscoreIndex == -1)
                {
                    MainChannel.AddMessage(new ChatMessage(Color.White,
                                                           "Your nickname is invalid or already in use. Please change your nickname in the login screen."));
                    UserINISettings.Instance.SkipConnectDialog.Value = false;
                    Disconnect();
                    return;
                }

                charList[lastNonUnderscoreIndex] = '_';
            }

            var sb = new StringBuilder();

            foreach (char c in charList)
            {
                sb.Append(c);
            }

            MainChannel.AddMessage(new ChatMessage(Color.White,
                                                   string.Format("Your name is already in use. Retrying with {0}...", sb.ToString())));

            ProgramConstants.PLAYERNAME = sb.ToString();
            connection.ChangeNickname();
        }
Esempio n. 15
0
 protected object ExecuteCommand(object par, bool toKill)
 {
     if (par is WpfGrid)
     {
         IList l = new ArrayList();
         SourceControl.Dispatcher.Invoke(DispatcherPriority.Normal,
                                         (Action) delegate
         {
             l = ((WpfGrid)par).SelectedItems;
         });
         foreach (Connection c in l)
         {
             if (c.ClientUniqueKey != Client.UniqueKey)
             {
                 MainChannel.PuntUser(c.ClientUniqueKey, "Punted by other user", toKill);
             }
         }
     }
     else if (par != null && par is string)
     {
         var s = (string)par;
         if (s == "All")
         {
             MainChannel.PuntUser(null, "Punted all", toKill);
         }
         else
         {
             MainChannel.PuntUser(s, "Punted by reference", toKill);
         }
     }
     else
     {
         Client.ClientStatus = ClientStatus.DisconnectPending;
         MainChannel.Disconnect();
     }
     return(null);
 }
Esempio n. 16
0
 protected override object ExecuteCommand(object message)
 {
     return(MainChannel.RequestUsers());
 }
Esempio n. 17
0
 private void DoGenericServerMessageReceived(string message)
 {
     MainChannel.AddMessage(new ChatMessage(null, Color.White, DateTime.Now, message));
 }
Esempio n. 18
0
 private void DoIncorrectChannelPassword(string channelName)
 {
     MainChannel.AddMessage(new ChatMessage(null, Color.White, DateTime.Now, "Incorrect password!"));
 }
 private void DoConnected()
 {
     connected = true;
     Connected?.Invoke(this, EventArgs.Empty);
     MainChannel.AddMessage(new ChatMessage("Connection to CnCNet established."));
 }
Esempio n. 20
0
 public void OnErrorReceived(string errorMessage)
 {
     MainChannel.AddMessage(new ChatMessage(null, Color.Red, DateTime.Now, errorMessage));
 }
 /// <summary>
 /// Connects to CnCNet.
 /// </summary>
 public void Connect()
 {
     disconnect = false;
     MainChannel.AddMessage(new ChatMessage("Connecting to CnCNet..."));
     connection.ConnectAsync();
 }
Esempio n. 22
0
 /// <summary>
 /// Connects to CnCNet.
 /// </summary>
 public void Connect()
 {
     disconnect = false;
     MainChannel.AddMessage(new ChatMessage(null, Color.White, DateTime.Now, "Connecting to CnCNet..."));
     connection.ConnectAsync();
 }
Esempio n. 23
0
 private void DoConnected()
 {
     connected = true;
     Connected?.Invoke(this, EventArgs.Empty);
     MainChannel.AddMessage(new ChatMessage(null, Color.White, DateTime.Now, "Connection to CnCNet established."));
 }
Esempio n. 24
0
        private void DoConnectAttemptFailed()
        {
            ConnectAttemptFailed?.Invoke(this, EventArgs.Empty);

            MainChannel.AddMessage(new ChatMessage(null, Color.Red, DateTime.Now, "Connecting to CnCNet failed!"));
        }
 public void OnErrorReceived(string errorMessage)
 {
     MainChannel.AddMessage(new ChatMessage(Color.Red, errorMessage));
 }
Esempio n. 26
0
 private void DoAttemptedServerChanged(string serverName)
 {
     MainChannel.AddMessage(new ChatMessage(null, Color.White, DateTime.Now, "Attempting connection to " + serverName));
     AttemptedServerChanged?.Invoke(this, new AttemptedServerEventArgs(serverName));
 }
 private void DoGenericServerMessageReceived(string message)
 {
     MainChannel.AddMessage(new ChatMessage(message));
 }