Ejemplo n.º 1
0
        private void OnConnect(IAsyncResult AsyncResult)
        {
            Socket ServerSock = (Socket)AsyncResult.AsyncState;

            ServerSock.EndConnect(AsyncResult);
            AppLog.WriteLine(5, "STATUS", "Connected.");
            ConnectDone.Set();
            IRCComm ServerComm = new IRCComm();

            ServerComm.ParentServerComm = this;
            ServerComm.WorkSocket       = ServerSock;
            AppLog.WriteLine(5, "STATUS", "Waiting for data...");
            ServerComm.WorkSocket.BeginReceive(ServerComm.Buffer, 0, IRCComm.BufferSize, 0, new AsyncCallback(OnDataReceived), ServerComm);
            if (ParentServer.Pass != "")
            {
                Send("PASS " + ParentServer.Pass);
                Send("USER " + ParentServer.Nick + " 8 * : " + ParentServer.RealName);
                Send("NICK " + ParentServer.Nick);
            }
            else
            {
                Send("USER " + ParentServer.Nick + " 8 * : " + ParentServer.RealName);
                Send("NICK " + ParentServer.Nick);
            }
        }
Ejemplo n.º 2
0
        private void OnDataReceived(IAsyncResult AsyncResult)
        {
            IRCComm ServerComm  = (IRCComm)AsyncResult.AsyncState;
            Socket  SockHandler = ServerComm.WorkSocket;

            try {
                int BytesRead = SockHandler.EndReceive(AsyncResult);
                if (BytesRead > 0)
                {
                    char[] TempByteArr     = new char[BytesRead];
                    int    ReceivedLen     = Encoding.UTF8.GetChars(ServerComm.Buffer, 0, BytesRead, TempByteArr, 0);
                    char[] ReceivedCharArr = new char[ReceivedLen];
                    Array.Copy(TempByteArr, ReceivedCharArr, ReceivedLen);
                    String ReceivedData = new String(ReceivedCharArr);
                    ServerComm.StringBuffer += ReceivedData;
                    if (Functions.OccurancesInString(ServerComm.StringBuffer, "\n") > 0)
                    {
                        String[] splitIncommingData = ServerComm.StringBuffer.Split("\n".ToCharArray());
                        for (int i = 0; i < splitIncommingData.Length; i++)
                        {
                            if (splitIncommingData[i].Contains("\r"))
                            {
                                if (splitIncommingData[i].Length + 1 > ServerComm.StringBuffer.Length)
                                {
                                    ServerComm.StringBuffer = ServerComm.StringBuffer.Remove(0, splitIncommingData[i].Length);
                                }
                                else
                                {
                                    ServerComm.StringBuffer = ServerComm.StringBuffer.Remove(0, splitIncommingData[i].Length + 1);
                                }
                                ParentServer.ParseRawLine(splitIncommingData[i].Substring(0, splitIncommingData[i].Length - 1));
                            }
                        }
                    }
                    SockHandler.BeginReceive(ServerComm.Buffer, 0, IRCComm.BufferSize, 0, new AsyncCallback(OnDataReceived), ServerComm);
                }
                else
                {
                    Close(SockHandler);
                }
            } catch (SocketException Se) {
                if (Se.ErrorCode == 10054)
                {
                    Close(SockHandler);
                }
            }
        }
 private void OnConnect(IAsyncResult AsyncResult)
 {
     Socket ServerSock = (Socket)AsyncResult.AsyncState;
     ServerSock.EndConnect(AsyncResult);
     AppLog.WriteLine(5, "STATUS", "Connected.");
     ConnectDone.Set();
     IRCComm ServerComm = new IRCComm();
     ServerComm.ParentServerComm = this;
     ServerComm.WorkSocket = ServerSock;
     AppLog.WriteLine(5, "STATUS", "Waiting for data...");
     ServerComm.WorkSocket.BeginReceive(ServerComm.Buffer, 0, IRCComm.BufferSize, 0, new AsyncCallback(OnDataReceived), ServerComm);
     if (ParentServer.Pass != "") {
         Send("PASS " + ParentServer.Pass);
         Send("USER " + ParentServer.Nick + " 8 * : " + ParentServer.RealName);
         Send("NICK " + ParentServer.Nick);
     } else {
         Send("USER " + ParentServer.Nick + " 8 * : " + ParentServer.RealName);
         Send("NICK " + ParentServer.Nick);
     }
 }