コード例 #1
0
 public override string HandleCommand(IRCCommandBase command, Session session)
 {
     if (command is QUITCommand)
     {
         QUITCommand quitCommand = (QUITCommand)command;
         ServerBackend.Instance.Users.Remove(session.User);
         session.ConnectionState = ConnectionState.Destroyed;
         ServerBackend.Instance.ClientSessions.Remove(session);
         return("OK");
     }
     else
     {
         throw new ArgumentException();
     }
 }
コード例 #2
0
ファイル: IRCServer.cs プロジェクト: frareipa/simulation1
        public void ReceiveCommand(IAsyncResult result)
        {
            Session newsession = (Session)result.AsyncState;

            newsession.Socket.EndReceive(result);
            if (Encoding.ASCII.GetString(newsession.Buffer).Split('\0').Length == 0)
            {
                IRCCommandBase q = new QUITCommand(null);
                q.ExecuteCommand(newsession);
            }
            else
            {
                string response;
                try
                {
                    response = CommandFactory.GetCommandFromMessage(Encoding.ASCII.GetString(newsession.Buffer), newsession).ExecuteCommand(newsession);
                    newsession.Socket.BeginSend(Encoding.ASCII.GetBytes(response), 0, Encoding.ASCII.GetBytes(response).Length, SocketFlags.None, new AsyncCallback(FinalizeSending), newsession);
                }
                catch
                {
                    newsession.Socket.BeginSend(newsession.Buffer, 0, newsession.Buffer.Length, SocketFlags.None, new AsyncCallback(FinalizeSending), newsession);
                }
            }
        }