Beispiel #1
0
        private void appFileAcceptHandler()
        {
            if (OnServerLog != null)
            {
                OnServerLog("\n<< FileAccept数据处理 >>");
            }
            int neckLen =
                (int)(System.Text.Encoding.UTF8.GetChars(data, 1, 2)[0]);

            if (neckLen == 0)
            {
                Console.WriteLine("文件接受信息中含有非法参数,目标客户端昵称长度必须非0");
            }
            else
            {
                // 传递对提供客户端的文件接受
                String neckName     = System.Text.Encoding.UTF8.GetString(data, 2, neckLen);
                String safeFileName = System.Text.Encoding.UTF8.GetString(data, 2 + neckLen, bytesRead - 2 - neckLen);

                ChaitMirror targetClient = (ChaitMirror)ChaitServer.Instance.Clients[neckName];
                String      msgStr       =
                    System.Convert.ToChar(CProtocol.FileAccept).ToString() +
                    (Char)System.Text.Encoding.UTF8.GetBytes(ClientNeck).Length +
                    ClientNeck +
                    (Char)System.Text.Encoding.UTF8.GetBytes(safeFileName).Length +
                    safeFileName +
                    ClientIP;
                targetClient.transSendMsg(msgStr);
                OnServerLog(String.Format("'{0}'接受了'{1}'发送文件'{2}'的请求", ClientNeck, neckName, safeFileName));
            }
            if (OnServerLog != null)
            {
                OnServerLog("\n");
            }
        }
Beispiel #2
0
        private void appChat()
        {
            if (OnServerLog != null)
            {
                OnServerLog("\n<< Chat数据处理 >>");
            }
            try
            {
                int    neckLen  = (int)(System.Text.Encoding.UTF8.GetChars(data, 1, 1)[0]);
                String neckName = System.Text.Encoding.UTF8.GetString(data, 2, neckLen);
                String message  = System.Text.Encoding.UTF8.GetString(data, 2 + neckLen, bytesRead - 2 - neckLen);

                ChaitMirror targetClient = (ChaitMirror)ChaitServer.Instance.Clients[neckName];
                String      msgStr       =
                    System.Convert.ToChar(CProtocol.Chat).ToString() +
                    (Char)System.Text.Encoding.UTF8.GetBytes(ClientNeck).Length +
                    ClientNeck +
                    message;
                targetClient.transSendMsg(msgStr);

                if (OnServerLog != null)
                {
                    OnServerLog("[数据][私聊消息][来源:" + ClientNeck + "][目标:" + neckName + "][消息:******]");
                }
            }
            catch (Exception)
            {
                throw;
            }
            if (OnServerLog != null)
            {
                OnServerLog("\n");
            }
        }
Beispiel #3
0
        // 端口侦听线程
        private void serverListen()
        {
            while (true)
            {
                ChaitMirror newClient =
                    new ChaitMirror(listener.AcceptTcpClient());
                newClient.OnServerLog = serverLogHandler;

                NewClients.Add(newClient.RemoteEndPoint, newClient);
            }
        }