示例#1
0
 public static void Logout(UserSocketState sock)
 {
     if (sock.Map != null && sock.PlayerContext != null)
     {
         sock.Map.QuitMap(sock.PlayerContext);
         ForgetiveServer.Close(sock, "客户端无响应");
         sock.Close();
     }
 }
示例#2
0
 void SendSuccess(IAsyncResult result)
 {
     try
     {
         __SOCKETLOCK = false;
         ((Socket)result.AsyncState).EndSend(result);
     }
     catch
     {
         ForgetiveServer.Close(this);
     }
 }
示例#3
0
        public static ServerResult LogDevice(string machine)
        {
            ServerResult ret = new ServerResult(false, "");
            string       key = key_device.GetFirstXWithY(machine);

            if (key == null)
            {
                ret.IsSuccess = false;
                ret.Note      = "nomac";
            }
            else if (key_banned.GetFirstYWithX(key) == "{notbanned}")
            {
                for (int i = 0; i < ForgetiveServer.Users.Count; i++)
                {
                    UserSocketState sock = ForgetiveServer.Users[i];
                    if (sock == null)
                    {
                        ForgetiveServer.Users.RemoveAt(i);
                        i--;
                        continue;
                    }
                    if (sock.UsedKey == key)
                    {
                        ForgetiveServer.Close(sock, null, false);
                        ForgetiveServer.Users.RemoveAt(i);
                        i--;
                        continue;
                    }
                }
                ret.IsSuccess  = true;
                ret.InternalEx = key;
                ret.Note       = ForgetiveServer.Base64Encode(key_nick.GetFirstYWithX(key));
                Logger.WriteLine("设备ID:{0}已登陆密匙:{1}", machine, key);
            }
            else
            {
                ret.IsSuccess = false;
                ret.Note      = "banned";
            }
            return(ret);
        }
示例#4
0
        ServerResult OnRecvServerData()
        {
            string       cmd = RecvParams[0];
            ServerResult ret;

            switch (cmd)
            {
            case "rename":
                ret = new ServerResult();
                lock (Program.key_nick)
                {
                    string rec = ForgetiveServer.Base64Decode(RecvParams[1]);
                    if (CheckNickName(rec))
                    {
                        Program.key_nick.SetXToY(UsedKey, rec);
                        NickName      = rec;
                        ret.IsSuccess = true;
                    }
                    else
                    {
                        ret.IsSuccess = false;
                    }
                }
                return(ret);

            case "minf":
                return(new ServerResult(true, XCoin + ";" + BP));

            case "join":
                if (RecvParams.Length == 2)
                {
                    GlobalServer.JoinMap(this, RecvParams[1]);
                }
                break;
            }
            return(null);
        }
示例#5
0
 public void RecvData()
 {
     RecvParams = RecvString.Split('\n');
     if (!IsMatched)
     {
         ServerResult ret;
         if (IsMatchVersion)
         {
             if (RecvParams.Length == 3)
             {
                 if (RecvParams[0] == "reg")
                 {
                     ret = Program.RegDevice(RecvParams[1], RecvParams[2]);
                     if (ret.IsSuccess)
                     {
                         IsMatched = true;
                         UsedKey   = RecvParams[1];
                         NickName  = Program.key_nick.GetFirstYWithX(UsedKey, GetMD5(UsedKey));
                     }
                     Send(ret.Value());
                     return;
                 }
                 else
                 {
                     return;
                 }
             }
         }
         if (RecvString.Contains("PUBLICTIMESTAMP"))
         {
             if (RecvString.Split(';').Length == 2)
             {
                 string s = RecvString.Split(';')[1];
                 if (int.TryParse(s, out int v))
                 {
                     version = new VersionControl.Version(v);
                     if (ServerVersion.CheckVersion(v))
                     {
                         IsMatchVersion = true;
                     }
                 }
             }
             Send(DateTime.Now.ToBinary().ToString() + ";" + IsMatchVersion);
             return;
         }
         if (IsMatchVersion)
         {
             //登陆取到的设备
             ret = Program.LogDevice(RecvString);
             if (ret.IsSuccess)
             {
                 IsMatched = true;
                 UsedKey   = ret.InternalEx;
                 //在key:nick表中获取玩家昵称,若为空用Key的MD5值临时代替
                 NickName = Program.key_nick.GetFirstYWithX(UsedKey, GetMD5(UsedKey));
                 Send(ret.Value());
             }
             else
             {
                 if (ret.Note == "nomac")
                 {
                     if (genKey.Gen())
                     {
                         ret.Note = genKey.Result;
                     }
                 }
                 Send(ret.Value());
             }
         }
         return;
     }
     if (RecvParams.Length > 1)
     {
         if (RecvParams[0] == "map")
         {
             if (PlayerContext != null)
             {
                 PlayerContext.EvalCommand(RecvParams);
             }
             return;
         }
     }
     try
     {
         ServerResult sresult = OnRecvServerData();
         if (sresult != null)
         {
             Send(sresult);
         }
     }
     catch
     {
         ConsoleColor color = Console.ForegroundColor;
         Console.ForegroundColor = ConsoleColor.Red;
         Console.Write("在处理来自");
         SayPlayerInfo();
         Logger.WriteLine("的数据时,遇到了错误。");
         Logger.WriteLine("这通常说明此玩家有异常的游戏行为或使用了错误版本的客户端。");
         ForgetiveServer.Close(this);
         Console.ForegroundColor = color;
     }
 }
示例#6
0
        static void Main(string[] args)
        {
            __InitExceptionEventer();

            #region 主要环境初始化和硬件检查
            StartTime               = DateTime.Now;
            Console.Title           = "XCWorld Server - Forgetive";
            ItemStorage.OpenedFiles = new List <FileStream>();
            if (args.Length != 0)
            {
                Data.InitData(args[0]);
            }
            else
            {
                return;
            }
            Logger.Init();

#if !__LINUX_ARM
            CheckHardware();
#endif

            #endregion

            #region 参数处理
            if (args.Length == 1)
            {
            }
            else if (args.Length == 2)
            {
#if DEBUG
                sudoExecutionContent = args[1];
                isDebugMode          = true;
                Logger.WriteLine(LogLevel.Info, "已启用Debug模式");
#else
                Logger.WriteLine(LogLevel.Error, "正式版不允许手动设置权限");
                return;
#endif
            }
            else
            {
                Logger.WriteLine(LogLevel.Error, "仅允许添加一个具有完全权限执行体的名称");
                return;
            }

#if DEBUG
            Logger.WriteLine(LogLevel.Warning, "Forgetive Server SDK版");
            Logger.WriteLine(LogLevel.Warning, "测试版支持对应版本的 Forgetive Developer For Win10 客户端");
#endif
            if (!Environment.Is64BitProcess)
            {
                Logger.WriteLine(LogLevel.Error, "Forgetive Server 运行在32位进程下,进程仅允许最高1.5GB内存,这将导致不可恢复的错误。");
            }
            #endregion

            Logger.WriteLine("Forgetive Server 初始化网络...");

            key_device         = Data.GetTable("key", "device");
            key_banned         = Data.GetTable("key", "banned");
            key_nick           = Data.GetTable("key", "nick");
            nick_xcoin         = Data.GetTable("nick", "xcoin");
            nick_bp            = Data.GetTable("nick", "bp");
            nick_isop          = Data.GetTable("nick", "isop");
            nick_newplayerstep = Data.GetTable("nick", "newplayerstep");

            ForgetiveServer.Init();
            ItemUsage.Init();
            ItemStorage.Init();
            ServerVersion.Init();
            engine = new CommandEngine();

            assemblies = new List <Assembly>();
            assemblies.Add(Assembly.GetAssembly(typeof(Program)));
            assembliesMd5 = new List <string>();
            assembliesMd5.Add("INNEREXT");
            Logger.WriteLine(LogLevel.Info, "加载 Forgetive EXT {0}", "ForgetiveServer [Inner]");

            DirectoryInfo info = new DirectoryInfo(Data.RootPath + "/Extension");
            if (!info.Exists)
            {
                info.Create();
            }
            FileInfo[] files = info.GetFiles();
            for (int i = 0; i < files.Length; i++)
            {
                if (files[i].Extension == ".dll")
                {
                    try
                    {
                        assembliesMd5.Add(Hash(files[i].FullName));
                        Assembly assembly = Assembly.LoadFile(files[i].FullName);
                        assemblies.Add(assembly);
                    }
                    catch
                    {
                        Logger.WriteLine(LogLevel.Warning, "无法加载 {0} : 无效的 Forgetive EXT 文件", files[i].Name);
                        assembliesMd5.RemoveAt(assembliesMd5.Count - 1);
                    }
                    Logger.WriteLine(LogLevel.Info, "加载 Forgetive EXT {0}", files[i].Name);
                }
            }
            ExecutionContent.Load(assemblies.ToArray());

            List <Assembly> ass = new List <Assembly>(assemblies);
            ass.Add(Assembly.GetEntryAssembly());
            GlobalServer.Init(ass.ToArray());
            NPCManager.Init();

            TimeSpan total = DateTime.Now - StartTime;
            Logger.WriteLine(LogLevel.Default, "初始化完成({0}s),使用help查看指令列表", total.TotalSeconds);

            while (true)
            {
                string cmd = Console.ReadLine();
                engine.Execute(cmd);
            }
        }