Пример #1
0
        static void Core_ShuttingDown(object sender, EventArgs e)
        {
            if (ultimaSocket != null)
            {
                Trace.WriteLine(String.Format("Warning: Exiting with opened socket {0}. Closing..", ultimaSocket.Socket), "Communication");

                WinSock.closesocket(ultimaSocket.Socket);
                ultimaSocket = null;
            }
        }
Пример #2
0
        private void InternalSendToServer(byte[] data)
        {
            CommunicationManager.BandwidthManager.Upload(data.Length);

            int sent = WinSock.send(socket, data, data.Length, 0);

            if (sent != data.Length)
            {
                UO.Print(Env.DefaultErrorColor, "Fatal: Error sending message to server.");
                System.Diagnostics.Trace.WriteLine("Error sending message to server.", "Communication");
            }
        }
Пример #3
0
        /// <summary>
        /// Client is requesting data.
        /// </summary>
        public static int OnRecv(long s, byte[] buff, int len, int flags)
        {
            CheckThread();

            lock (SyncRoot) {
                if (ultimaSocket != null && ultimaSocket.Socket == s)
                {
                    return(ultimaSocket.Recv(s, buff, len, flags));
                }
                else
                {
                    return(WinSock.recv(s, buff, len, flags));
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Reads data from server.
        /// </summary>
        public void ReceiveData()
        {
            CommunicationManager.CheckThread();

            lock (CommunicationManager.SyncRoot)
            {
                const int BuffLen = 65536;

                byte[] encryptedBuffer = new byte[BuffLen];
                int    readBytes       = WinSock.recv(socket, encryptedBuffer, BuffLen, 0);

                if (readBytes > 0)
                {
                    CommunicationManager.BandwidthManager.Download(readBytes);

                    byte[] decryptedBuffer = serverEncryption.Decrypt(encryptedBuffer, readBytes);
                    ProcessMessages(decryptedBuffer, true);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Client is sending data.
        /// </summary>
        public static int OnSend(long s, byte[] buff, int len, int flags)
        {
            CheckThread();

            lock (SyncRoot) {
                if (ultimaSocket != null && ultimaSocket.Socket == s)
                {
                    if (redirecting)
                    {
                        Trace.WriteLine("Warning: Client is reusing login socket as game socket.", "Communication");
                        ultimaSocket = new GameSocket(s, ultimaSocket.Address, ultimaSocket.Port, loginSeed);
                        redirecting  = false;
                    }

                    return(ultimaSocket.Send(s, buff, len, flags));
                }
                else
                {
                    return(WinSock.send(s, buff, len, flags));
                }
            }
        }