A class containing the WebSocket proxy layer
Пример #1
0
        public static void OnReceiveFromWebSocket(WebSocketClient client, byte[] data, int length)
        {
            try {
                switch ((char)data [0])
                {
                // Reconnect
                case 'R':
                {
                    if (client.UOSocket != null && client.UOSocket.Connected)
                    {
                        client.UOSocket.Close();
                    }
                    goto case 'C';
                }

                // Connect
                case 'C':
                {
                    string[] strData = Encoding.ASCII.GetString(data, 0, data.Length).Split(' ');
                    for (int i = 0; i < strData.Length; i++)
                    {
                        Console.Write(strData [i] + ",");
                    }
                    client.UOSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    Console.WriteLine(string.Join(",", strData));
                    client.UOSocket.BeginConnect(strData [1], int.Parse(strData [2]), new AsyncCallback(UOConnectCallback), client);
                    break;
                }

                // Version
                case 'V':
                {
                    GameProxy.Send(client, "Version {0}", UOJS.Version);
                    break;
                }


                default:
                {
                    client.UOSocket.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(UOSendCallback), client);
                    break;
                }
                }
            } catch (Exception e) {
                UOJS.Log("Client [d/c]: Threw {0}... closing!", e.GetType());
                UOJS.Log(e.StackTrace);
                client.Close();
            }
        }
Пример #2
0
        /// <summary>
        /// Initialize this instance.
        /// </summary>
        public static void Initialize()
        {
            if (!File.Exists(UltimaDllLocation))
            {
                UOJS.Log("Error: Cannot find Ultima.dll");
                return;
            }
            if (WebDirectory.Length <= 0 || !InitializeFiles())
            {
                UOJS.Log("Error: WebDirectory (\"{0}\") does not exist.", WebDirectory);
                return;
            }

            m_Ultima = Assembly.LoadFrom(UltimaDllLocation);
            m_SHA1   = SHA1.Create();

            UOJS.Log("Starting UOJS (version {0}, Ultima version {1}, port {2})", UOJS.Version, System.Diagnostics.FileVersionInfo.GetVersionInfo(m_Ultima.Location).FileVersion, ListeningPort);
            GameProxy.BeginListening();
        }
Пример #3
0
 public static void Send(WebSocketClient client, string format, params object[] o)
 {
     GameProxy.Send(client, m_Encoding.GetBytes(string.Format(format, o)), RequestType.WebRequest, false);
 }