Home Database Mysql Tutorial 关于游戏合服的资料

关于游戏合服的资料

Jun 07, 2016 pm 05:42 PM
about game material

原网址: 我们的游戏上个星期经历了第一个数据合服。简单说,就是把2个数据库合并在一个数据库,让2个服务器的玩家一起玩。 过程简直是惊心动魄,最终还是安全完成任务。 本文就分享下合服的各种技术细节。 需求说明: -------------------------- 要把2个服

原网址:  

我们的游戏上个星期经历了第一个数据合服。简单说,香港空间,就是把2个数据库合并在一个数据库,让2个服务器的玩家一起玩。

过程简直是惊心动魄,最终还是安全完成任务。

本文就分享下合服的各种技术细节。

 

需求说明:

--------------------------

要把2个服务器玩家合并,首先外部对玩家而言是不变的,包括了登陆游戏的URL,游戏中的角色等;但是物理上,确是一台服务器一个数据库。

简单的说,一服的玩家用一服入口登陆,玩一服账号;二服的玩家用二服入口登陆,玩二服账号;

即使我只有1个账号,但是不同入口登陆,依然能使用不同游戏账号进行游戏。

 

数据库设计

--------------------------

要实现合服,首先表主键必须全部使用代码生成,并用服务器编码作为前缀。

例如我的一服表主键就是 001GMxxxxxxxxxxxxxxxx。 二服就是002GMxxxxxxxxxxxxxxxx。这样合服的时候,就不需要对数据进行预处理了。直接导入。

 

其次,使用平台用户使用一个账号,登陆不同服,要获得不同账号,因此在游戏的玩家表,要通过服务器编码进行区分,例如:

Usr_Profile

:usercode 主键

:username 平台账号

:servercode 服务器编码

这样,根据传入的username+servercode就知道应该获取什么服务器账号了。

 

游戏中,玩家通过昵称识别对方,因此合服的时候,必须对昵称进行修正,防止重复,因此所有昵称都要添加后缀。我们最终方案就是添加 .x服 这个后缀。

 

有了这3方面保证,合服就变得简单了。(简单个屁。。。)

 

合服流程

--------------------------------

1. 数据库分析准备

做事前都要先准备。因此首先要对数据库表结构进行分析,判断什么表结构需要合服,什么可以忽略。

我们游戏有60多张表,其中仅仅27张表需要合并,其他的都是配置表、日志表,都不需要合并。

 

2. 数据备份

这部不用说了,首先要对数据库全备份,防止操作失误,导致数据丢失了。一般就在本机MySQL新建一个backup数据库, 然后使用bult insert进行复制,速度很快。当然,备份的时候,对于体积很大的日志表,可以跳过了。

 

3. 数据删减

这部分很重要,一个网页游戏有接近80%的账号是死号,因此合服的时候必须先过滤掉死号。规则如下:等级小于10级、没有充值、最近登录时间大于30天的,全部清除。

然后,就是上文提到的27张表中,与被淘汰账号相关的数据,也清除。

这个清除量实际上非常大的,我有张数据表接近30W数据,结果一清就清了20W,超级舒服。

 

4. 数据检测

这部分也很重要,因为我们第二个服务器当时配置错了,没有使用服务器编码作为主键,导致与一服数据存在冲突的可能,因此需要对27张表的主键进行检测,判断前缀是否002,如果不是,就要进行手动修正了。

 

5. 数据修正

这块主要针对存在主键冲突的数据进行修正,一般用SQL即可,大概耗时30~60分钟,我就用个SQL,例如 update xxx set pk = concat('001',substring(pk,4)),进行数据修复。

当然,修复前,需要对表结构进行分析,不能出现遗漏,香港服务器,特别是外键关联。

 

6. 数据导出

不要尝试使用代码等方式进行合服,速度太慢了。我使用SQLYog,对所有表进行导出,其中插入配置为Bult Insert,导入速度非常快。

 

7. 数据导入测试

最终导入的时候,要测试,看看导出的SQL是否存在问题。

 

8. 导入。

这部完成,合服成功了。

 

貌似非常简单的步骤,实际上却问题多多。接下来我将说明实际部署中存在的陷阱。

 

 

合服 生存大考验

------------------------------

1. 合服的表结构不匹配

当时我合服的时候,发现表总是导不进去,提示主键重复。不可能的啊。。从一个不重复主键的表导入会提示重复?

检查了很久发现,服1的主键是21位,服2的主键是22位,结果导入的时候22位的主键自动省略了最后一位,自然会产生了主键重复。。。

 

2. SQLYog该死的bug

SQLYog改表结构竟然和实际表结构不对应。我明明修改了char(100),可是数据库一看,还是char(21). 最终只好用命令行修改。。

嗨。关键时候,这些工具总是找麻烦。

 

3.  SQLYog导入出错竟然没有提示

也是该死的工具问题,最后我使用navicat配合SQLYog进行操作。

 

4. 部分动态生成的数据,无法批量导入

例如竞技场排名,不允许出现相同排名。所以这块数据需要在玩家登陆的时候自动生成。此类型数据都是动态生成的,无法通过批量修正,都需要通过游戏逻辑进行补全。

因此,合服的时候,这块数据将不参与合并。

 

合服历险记

------------------------------

说了这么多理论知识,接下来就说说那天我合服的经过。本来在测试机上一切顺利的,不到2个小时就合并了。可是真正操作起来, 却用了8个小时。。。。

 

开始还顺利,3个多小时就做好了数据备份、删除、修正。可是导入的时候发现总是提示主键冲突,于是不断找原因,1个小时过去,才发现原来表结构不匹配。晕死。

 

接下来导完数据,4个小时过去了,开服。一运行,玩家就投诉了,说中文乱码、丢失装备、丢失武将。

 

丢失装备、武将问题,我又花了1个小时检查,原来是潜在部分主键仍然丢失最后1位,导致找不到。这个时候,我不能停机,因此我对比2个数据库有差异的表,生成一堆update的SQL,然后手动操作。可是发现SQL多了,SQLYog会卡死,游戏也会卡死。我只好开了10多个SQLYog,采用并行方法,把SQL拆分成50一组,进行手动操作。。累死了。

 

对于武将名字乱码,是当时生成SQL文件的时候,编码格式错误了。可是武将数据接近有3W条,不可能进行手动更新了,因此我写了个更新程序,进行后台更新。这块就花了1小时。

 

终于游戏Exception少了,本来可以歇口气了,结果运营说,玩家充值失败!我检查代码,原来充值接口没有使用servercode去区分玩家账号,又是疏忽。

 

第二天,运营又投诉说,商会采集资源失败,回去检查,才发现原来漏了对账号中商会主键进行修正,又是疏忽。

 

小结

----------------------------

本来已经提前预演了2天,没有问题,可是上到战场还是错漏百出。

如果准备过于详细,会导致发展缓慢。如果准备不充分,又会很多问题。这个是个进退两难的情况。最终,我偏向了迅速准备,快速修正的方案。

毕竟,预演的时候找不到的问题,网站空间,给再多的时间也不一定找到。还不如直接上战场,随机应变。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should the CPU utilization be when gaming? What should the CPU utilization be when gaming? Feb 19, 2024 am 11:21 AM

It's common for games to slow down your computer because they consume a lot of resources. It's crucial to understand your CPU usage when gaming so you can avoid overloading it. Therefore, keeping track of appropriate CPU usage is key to keeping your gaming experience smooth. In this article, we'll look at the appropriate CPU usage you should achieve while your game is running. CPU utilization during gaming CPU utilization is an important indicator of processor workload and depends on the performance specifications of the CPU. More powerful CPUs generally have higher usage. A CPU with more cores and threads can improve the overall performance of your system. Multi-threading support helps unleash the full potential of your CPU. In games, CPU usage depends on processor utilization, which can affect the game

Nvgpucomp64.dll causes Windows PC games to crash; Nvgpucomp64.dll causes Windows PC games to crash; Mar 26, 2024 am 08:20 AM

If Nvgpucomp64.dll is causing your game to crash frequently, the solutions provided here may help you. This problem is usually caused by outdated or corrupted graphics card drivers, corrupted game files, etc. Fixing these issues can help you deal with game crashes. The Nvgpucomp64.dll file is associated with NVIDIA graphics cards. When this file crashes, your game will crash too. This usually happens in games like LordsoftheFallen, LiesofP, RocketLeague, and ApexLegends. Nvgpucomp64.dll crashes games on Windows PC if N

NAT Boost vs. Qos for games; which one is better? NAT Boost vs. Qos for games; which one is better? Feb 19, 2024 pm 07:00 PM

In today's situation where almost all games are online, it is not advisable to ignore the optimization of home network. Almost all routers are equipped with NATBoost and QoS features designed to enhance users' gaming experience. This article will explore the definition, advantages and disadvantages of NATBoost and QoS. NATBoost vs. Qos for games; which one is better? NATBoost, also known as Network Address Translation Boost, is a feature built into routers that improves their performance. It's especially important for gaming because it helps reduce network latency, which is the time it takes for data to be transferred between the gaming device and the server. By optimizing the data processing method within the router, NATBoost achieves faster data processing speed and lower latency, thus changing the

NVIDIA launches RTX HDR function: unsupported games use AI filters to achieve HDR gorgeous visual effects NVIDIA launches RTX HDR function: unsupported games use AI filters to achieve HDR gorgeous visual effects Feb 24, 2024 pm 06:37 PM

According to news from this website on February 23, NVIDIA updated and launched the NVIDIA‏‏ application last night, providing players with a new unified GPU control center, allowing players to capture wonderful moments through the powerful recording tool provided by the in-game floating window. In this update, NVIDIA also introduced the RTXHDR function. The official introduction is attached to this site: RTXHDR is a new AI-empowered Freestyle filter that can seamlessly introduce the gorgeous visual effects of high dynamic range (HDR) into In games that do not originally support HDR. All you need is an HDR-compatible monitor to use this feature with a wide range of DirectX and Vulkan-based games. After the player enables the RTXHDR function, the game will run even if it does not support HD

Introduction to how to download and install the superpeople game Introduction to how to download and install the superpeople game Mar 30, 2024 pm 04:01 PM

The superpeople game can be downloaded through the steam client. The size of this game is about 28G. It usually takes one and a half hours to download and install. Here is a specific download and installation tutorial for you! New method to apply for global closed testing 1) Search for "SUPERPEOPLE" in the Steam store (steam client download) 2) Click "Request access to SUPERPEOPLE closed testing" at the bottom of the "SUPERPEOPLE" store page 3) After clicking the request access button, The "SUPERPEOPLECBT" game can be confirmed in the Steam library 4) Click the install button in "SUPERPEOPLECBT" and download

Where is Spider Solitaire in win11 How to play Spider Solitaire game in win11 Where is Spider Solitaire in win11 How to play Spider Solitaire game in win11 Mar 01, 2024 am 11:37 AM

Friends who have played enough AAA masterpieces and mobile games, do you want to relive the computer games of your childhood? Then let’s look for Spider Solitaire in Windows 11 together! Click the Start menu on the interface, click the "All Apps" button; click "All Apps". Find and select "MicrosoftSolitaireCollection", which is Microsoft's Solitaire series game application; Solitaire series game selection. After loading is complete, enter the selection interface and find "Spider Solitaire"; select "Spider Solitaire". Although the interface has changed slightly, it is still the same as before

Thrustmaster control panel not working or displaying properly [Fixed] Thrustmaster control panel not working or displaying properly [Fixed] Feb 19, 2024 am 10:45 AM

Thrustmaster is a company that specializes in the production of gaming wheels and other gaming accessories. Its wheel products are very popular in the gaming community. Thrustmaster wheel settings can be installed and adjusted using the Thrustmaster control panel. If you encounter problems with the control panel not working or displaying, it may affect your gaming experience. Therefore, when this happens, you need to check whether the connection is normal and ensure that the software driver is installed correctly and updated to the latest version. In addition, you can also try to restart the device or reconnect the device to resolve possible failures. When you encounter problems, you can refer to Thrustmaster's official website or contact customer service for further help. How to access Thrustma

ASUS releases BIOS update to improve gaming stability on Intel's 13th/14th generation processors ASUS releases BIOS update to improve gaming stability on Intel's 13th/14th generation processors Apr 20, 2024 pm 05:01 PM

According to news from this site on April 20, ASUS recently released a BIOS update, which improves instability such as crashes when running games on Intel's 13th/14th generation processors. This site previously reported that players reported problems including that when running the PC demo version of Bandai Namco's fighting game "Tekken 8", even if the computer has sufficient memory and video memory, the system will crash and prompt an error message indicating insufficient memory. Similar crashing issues have also appeared in many games such as "Battlefield 2042", "Remnant 2", "Fortnite", "Lord of the Fallen", "Hogwarts Legacy" and "The Finals". RAD published a long article in February this year, explaining that the game crash problem is a combination of BIOS settings, high clock frequency and high power consumption of Intel processors.

See all articles