コード例 #1
0
        public void CHAR_SEND_PACKET(Client client, ApiPacket packet)
        {
            var op     = packet.ReadByte();
            var charId = packet.ReadUInt32();
            var data   = packet.ReadByteArray();

            Player player = null;

            lock (Player._Players)
                player = Player._Players.Where(e => e.CharacterId == charId).FirstOrDefault();
            if (player != null)
            {
                var Out = new PacketOut(op);
                Out.Write(data, 0, data.Length);
                player.SendPacket(Out);
            }
        }
コード例 #2
0
        public void EXECUTE_SCRIPT(Client client, ApiPacket packet)
        {
            var name   = packet.ReadPascalString();
            var script = System.Text.ASCIIEncoding.ASCII.GetString(packet.ReadByteArray());

            int lineCount = 16;

            var template = @"using System;
                            using System.Collections.Generic;
                            using System.Linq;
                            using System.Linq.Expressions;
                            using System.Reflection;
                            using System.Text;
                            using System.Threading.Tasks;
                            using Common;
                            using FrameWork;

                            namespace WorldServer
                            {
                                public class ScriptEnv
                                {
		                            public void Execute()
		                            {
					                    [@@CODE@@]
		                            }
                                    private WorldServer.API.Client _client;
                                    private string _name;
                                    public ScriptEnv(WorldServer.API.Client client, string name)
                                    {
                                        _client = client;
                                        _name = name;
                                    }
                                }
                                public void Print(object data)
                                {
                                    WorldServer.API.Protocol.ScriptLog(_client, _name, data);
                                }
                            }";

            string result = template.Replace("[@@CODE@@]", script);
            string errors = "";

            System.CodeDom.Compiler.ICodeCompiler      compiler = new Microsoft.CSharp.CSharpCodeProvider().CreateCompiler();
            System.CodeDom.Compiler.CompilerParameters param    = new System.CodeDom.Compiler.CompilerParameters();
            param.GenerateExecutable = false;
            param.GenerateInMemory   = true;

            param.IncludeDebugInformation = false;

            param.ReferencedAssemblies.Add("System.Windows.Forms.dll");
            param.ReferencedAssemblies.Add("System.dll");
            param.ReferencedAssemblies.Add("System.Core.dll");
            param.ReferencedAssemblies.Add("System.Data.dll");
            param.ReferencedAssemblies.Add("System.Deployment.dll");
            param.ReferencedAssemblies.Add("System.Drawing.dll");
            param.ReferencedAssemblies.Add("WorldServer.exe");
            param.ReferencedAssemblies.Add("Common.dll");
            param.ReferencedAssemblies.Add("FrameWork.dll");

            System.CodeDom.Compiler.CompilerResults results = compiler.CompileAssemblyFromSource(param, result);

            if (results.Errors.Count != 0)
            {
                if (results.Errors.Count != 0)
                {
                    foreach (System.CodeDom.Compiler.CompilerError error in results.Errors)
                    {
                        SendScriptError(client, name, error.Line - lineCount, error.ErrorText);
                        break;
                    }
                }
            }
            else
            {
                try
                {
                    var obj = results.CompiledAssembly.CreateInstance("WorldServer.ScriptEnv", false, BindingFlags.CreateInstance, null,
                                                                      new object[] { client, name }, null, null);
                    obj.GetType().GetMethod("Execute").Invoke(obj, null);
                    SendScriptOK(client, name);
                }
                catch (Exception e)
                {
                    if (e.InnerException != null)
                    {
                        SendScriptException(client, name, e.InnerException.Message);
                    }
                    else
                    {
                        SendScriptException(client, name, e.Message);
                    }
                }
            }
        }