示例#1
0
文件: Program.cs 项目: gmhacx/NetCore
        private static void _server_OnDataRetrieved(eSock.Server sender, eSock.Server.eSockClient client, object[] data)
        {
            try
            {
                NetworkHeaders header = (NetworkHeaders)data[0];

                if (header == NetworkHeaders.Handshake)
                {
                    string key = Guid.NewGuid().ToString();
                    client.Send((byte)NetworkHeaders.AcceptHandshake, key);
                    client.Encryption.EncryptionKey = key;
                    client.Encryption.Enabled       = true;
                    return;
                }

                if (header == NetworkHeaders.RemoteCall)
                {
                    string function = (string)data[1];

                    if (!LoadedFunctions.ContainsKey(function))
                    {
                        Console.WriteLine("Invalid call ({0})", function);
                        client.Send(null);
                        return;
                    }

                    object[] args = (object[])data[2];

                    object result = LoadedFunctions[function].Invoke(null, args);
                    client.Send(result);
                    Console.WriteLine("Function Call ({0}) Value={1}", function, result);
                }
            }
            catch (Exception ex)
            {
                try
                {
                    client.Send(null);
                }
                catch { }
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: {0}", ex.Message);
                Console.ResetColor();
            }
        }
示例#2
0
        private void _server_OnDataRetrieved(eSock.Server sender, eSock.Server.eSockClient client, object[] data)
        {
            try
            {
                NetworkHeaders header = (NetworkHeaders)data[0];

                if (header == NetworkHeaders.Handshake)
                {
                    string key = Guid.NewGuid().ToString();
                    client.Send((byte)NetworkHeaders.AcceptHandshake, key);
                    client.Encryption.EncryptionKey = key;
                    client.Encryption.Enabled       = true;
                    return;
                }

                if (header == NetworkHeaders.RemoteCall)
                {
                    string functionHash = (string)data[1];

                    if (!LoadedFunctions.ContainsKey(functionHash))
                    {
                        Console.WriteLine("Invalid call ({0})", functionHash);
                        client.Send(null);
                        return;
                    }

                    object[] args = (object[])data[2];

                    RemoteFunction function = LoadedFunctions[functionHash];
                    client.Send(function.Execute(args));
                    Console.WriteLine("Function Call ({0}) Value={1}", function, functionHash);
                }
            }
            catch (Exception ex)
            {
                client.Send(null);
                LogError(ex);
            }
        }