1. Understand the game
1.1 What is a game
1.1.1 Definition of the game
Any activity outside the normal physiological needs of human beings can be called game
1.1.2 Classification of the game
RPG role-playing game, ACT action game, AVG adventure game, FPS first-person perspective shooting game, TPS third-person perspective shooting game, FTG fighting game, SPT sports game, RAC racing game, RTS real-time strategy game, STG shooting game, SLG strategy game, MSC music game, S IM life simulation game, TCG breeding game, CAG card game, LVG love game, GAL beautiful girl game, WAG mobile game, MMOPRG large-scale multiplayer online role-playing game, ARPG action role-playing game, ETC other games, animation games, MOBA multiplayer online technology competitive game
1.2 game development and division of labor
feasibility and planning research stage, analysis requirements stage, design stage, development stage, testing stage, system acceptance
development process: product project establishment, game design, development stage, testing stage, Alpha test (internal test of the project team), Beta testing (in-game testing), online promotion stage, operation stage
1.3 Current status analysis of the game industry
virtual reality equipment and content, mobile game control equipment, Internet + game entrepreneurship, e-sports live broadcast platform, original IP, H5 game
1.4 Key points for game server development
network knowledge (OSI reference model, socket, long connection, short connection), concurrent programming, design mode (singleton mode, factory mode, observer mode), database (MySQL, Mongo, memory database Redish, Memcache , Ehcache), gm operation tools, operation and maintenance knowledge (server deployment, architecture construction, load balancing, log management, database backup and recovery, disaster handling)
2. Environment construction
2.1 Windows development environment construction
2.1.1 Install JDK
Set Path variable, set CLASSPATH environment variable, set JAVA_HOME
2.1.2 Install Eclipse
2.1.3 Install database client tool
Navicat for MySQL (MySQL) : http://www.navicat.eom.cn/
MongoVUE (Mongo ) : http: / www.mongovue.com
RedisClient (Redis) : https:// github.com/caoxin /RedisClient
2.1.4 Install SSH tool
XShell: http://www.netsarang.com/products/xsh_overview.html
SSH: http://ultra.pr.erau.edu/~·jaffem/tutoriaVSSH _secure_ shell_ client.
2.1.5 Install other tools
Text editor
Ediψlus: https://www.ediφlus.com/download.htmlnl
Sublime Text: http://www.sublimetext.com/
Container
Tomcat: https://tomcat.apache.org/
JBoss: http://jbossas.jboss.o
JSON parsing tool
Online JSON Analysis: http://json.cn
2.2Mac OS X development environment to build
2.3Linux server environment to build
3. Network communication
3.1 communication protocol
TCP/IP model: link layer, network layer , transport layer, application layer
3.1.1 connection-oriented TCP
3 handshake to establish a connection
connection-oriented: Before communication, you must establish a reliable connection through three "handshakes"
safe and reliable: each communication must receive the other party's answer, otherwise the datagram is considered to be lost and retransmitted.
Full duplex communication: Once a connection is established, both parties can transmit data through the channel
Communication can only be established between two points
Stream-oriented communication: Communication transmission is carried out in the form of a stream.
3.1.2 UDP
3.1.3HTTP programming for datagrams
3.1.4Socket programming
Server listening, client request, connection confirmation
3.1.5 WebSocket programming
3.2Java NIO basic
3.2.1BIO programming (blocking IO)
3.2.2NIO programming (non-blocking IO)
Create 1 thread is responsible for handling IO events and distribution of events.
The event-driven mechanism monitors events asynchronously, but triggers after the event arrives.
threads communicate through wait notify and other methods, reducing unnecessary thread switching.
3.2.3AIO Programming (Asynchronous IO)
does not block and wait for the client to connect
3.3Mina Introduction and use
3.3.1 Overall architecture
3.3.2IoService
Responsible for IO related work
3.3.3IoF ilterChain
extension processor
3.3.4IoHandler
Business logic processing
3.3.5IoSession
corresponds to the IO connection between the client and the server
3.3.6 working principle
3.3.7Acceptor and Connector Thread
listen to the connection
3.3.8 Processor Thread
copy IO read and write operations
3.3.9 Thread mode
3.3.10 Request processing order
guarantee request IO request order
3.3.11Mina programming
3.4Netty introduction and use
3.4.1 Overall architecture
3.4.2 Zero copy
Netty receive and send by ByteBuffer, ByteBuffer Direct Buffers, that is, ByteBuffer directly uses memory outside the heap for Socket reading and writing, without the need to perform secondary copying of byte buffers
Netty Buffer object, can aggregate multiple ByteBuffer objects. If the user wants to operate multiple Buffers, he can first combine these Buffers, and then operate this combination Buffer
Netty uses transferTo for file transfer, and can directly send the data of the file buffer to the target Channel
3.4.3 Codec framework
FrameDecoder
FrameDecoder By maintaining DynamicChannelBuffer Stores the received data, it provides an abstract template, writes the entire decoding process in the template, and only implements the decode method in the subclass.
ReplayingDecoder
ReplayingDecoder The non-blocking decoding of FrameDecoder
ObjectEncoder and Objectoecoder
can code and serialize Java objects.
HttpRequestEncoder and HttpRequestDecoder
Netty can also implement HTTP servers, and HTTP requests and responses can be coded through HttpRequestEncoder HtφRequestDecoder.
3.4.4 Channel
3.4.5 ChannelEvent
3.4.6 ChannelPipeline
3.4.7 Netty Programming
4.Data interaction
4.1 Data transmission format
Network data size, network data security, implementation complexity, protocol universality
Data type: Custom binary Binary, open source protocol, Cultural Expo protocol
4.2JSON usage and parsing
4.3XML usage and parsing
4.4Google Protocol Introduction to Buffer and installation and compilation of Protobuffer using
4.4.1 Protobuffer syntax
4.4.2 Protobuffer
identifier. The identifier of the Protobuffer protocol is message enum, message represents message type, and enum represents enum type. After compiling through the Protobuffer compiler, they all generate a class in Java.
modifier
required: This segment cannot be empty, the value must be passed, otherwise the message cannot be initialized correctly.
optional: This field can be empty. Message can be correctly initialized regardless of whether the field is passed or not.
repeated: Repeated fields are equivalent to dynamic arrays. After being compiled into Java, they are List, but their data can be empty.
Data type
Package
Option, Option can define some commonly used job pages
4.4.3 Generate Java class
4.4.4 Eclipse protobuf-dt plug-in
4.4.5 Example program
5. Data cache and persistence
5.1 Game data storage
5.1.1 Data classification
global data (ranking information, alliance information, national information, arena information, etc. information shared by all players in the server), online player data, offline player data
5.1.2 Data cache method
5.1.3 Data persistence method
5.1.4 Database comparison
5.2 Introduction to MySql and the use of
5.3MongoDB and the use of
document storage, scalability, easy query, and security
5.4 Introduction to Memcache and the use of
5.5Redis and the use of
5.5.1Redis
fast speed, rich data types, operation atomicity, persistence, and rich application scenarios
5.5.3 Redis persistence
AOF mode refers to Redis During the execution process, all the write instructions will be recorded. When the data is restored, the command
RDB is executed in the order of recording at that time. The mode of the command
RDB is to store the data snapshots stored by Red is on disk and other media at different times. During the persistence process, Redis will first write the data to a temporary file. After the persistence process is completed, the file that was last persisted is replaced with the temporary file
5.5.4 The master-slave copy of Redis
6. Game logic
6.1 Logical architecture
6.1.1 Project directory
6.1.2 module introduction
core: core module
Gamelnit : The game server starts the shutdown class, responsible for loading and releasing server resources
Router : Processing logical processing message distribution for player requests to access
manager: Logical module
event event processing module.
module: logical module.
net: Network module, network framework used and network request processing, etc.
rpc: Responsible for remote service calls between logical servers and other servers.
NetFramework: simulates the network layer framework, responsible for encapsulation of network request response (I only write a simulation class here. Netty Mina and other network frameworks should be used in formal development >
NetHandler: simulates the network framework processing interface, responsible for handling the logic of the network framework.
NetHandlerlmpl: simulates the network framework processing interface implementation class
NetModule: simulates the network layer framework encapsulation, responsible for encapsulating the network framework.
ProtoIds: network request protocol number, protocol number for interaction between the client and the server
ProtoMessage: network request message body, message structure for interaction between the client and the server
ResultCode : Network response code, response code for the interaction between the client and the server return structure encapsulation
net.properties : Network configuration IP port file
task : Task module, timing tasks required in the game.
JobMgr: Job management class
QuartzManager: Quartz management class
TestJob: Test Job class
template : Static data, loading and reading of static data in the game.
DataLoader : Game server data loading class.
util : Tool class, required tool classes, such as database tool class, cache tool class, thread pool tool
CacheUtil Cache management class
DB Database management class
ExecutorPool Thread pool management class
test: Game server logic framework test class
6.2 logic flow
6.2.1 network module
6.2.2 thread pool
6.2.3 start server
6.2.4 logical request processing
6.2.5 close server
6.3 Event handler
In game server, there is often an event triggering mechanism, and the triggered events are usually executed asynchronously. The server internal event processor is used to disconnect the connection between modules. For example, after logging in, you must send a online notification to friends. After logging in, a login event will be triggered. All modules that pay attention to this event will still handle their own business. Avoid directly calling the interface of other modules after logging in.
6.4 timing tasks
In game servers, there is often a need to execute a certain logic regularly, such as daily check-in, hourly updates, player's attribute refresh at a certain moment, alliance or country's reputation value refreshes at a certain moment of the week. This series of requirements requires the use of timing tasks to realize the communication part between
6.5 RPC framework
communication between various server processes, and communication between multiple server processes. The current technology used is generally RPC
6.5.1 Json-rpc
6.5.2 Motan
Discovery services, subscription services and service notifications
Support Fail Over FailFast, and Server The number of consecutive failures reaches the specified number of times for high availability strategies such as heartbeat detection
supports priority low concurrency, contingency, hash, random request, polling Load balancing strategy
supports SPI extension
callable statistics logs and access logs
7. Game security
7.1 Necessity of game security
7.2 Login security
7.3 Game recharge
00 client requests to generate an order from the developer server.
client calls the intermodal SDK to open the payment interface and the player enters the payment information.
Intermodal SDK Sends order information to the intermodal server.
intermodal server records the order and sends the order to the developer server for payment verification.
developer server verifies order information. If the verification is successful, the shipment will be sent to the client and the verification result will be returned to the intermodal server.
intermodal server returns the order result to the client.
7.4SQL Inject
7.5 Communication protocol and message format
7.6 Integer overflow
7.7 Concurrent request
7.8 Logical vulnerability
7.9 Log system
8. Server architecture analysis
8.1 Evolution of server architecture
8.2 Analysis of the whole region same service architecture
8.2.1 coc architecture model analysis
8.2.2 COK Architecture model analysis
8.3 Partition server architecture analysis
8.4 Weak networked game architecture analysis
8.5MMORPG game architecture analysis
9. " Royal War " game development practical
9.1 Micro-competitive game introduction
9.2 Architecture analysis and construction
9.2.1 Functional analysis
9.2.2 Server deployment architecture
9.2.3 System architecture
. Communication mechanism, data processing, project management, system technical architecture diagram
9.3 Data persistence scheme
9.3.1 Data structure analysis
9.3.2 Operation using Morphia MongoDB
9.4Netty Network framework using
9.4.1 HTTP server implemented by Netty
9.4.2 Netty Server
9.5 Account system
9.6 Personal information
9.7 Hero card system
9.8 Treasure box system
9.9 Battle system
9.10 Client simulation
10. Game development technology prospects
10.1Egret
10.2Cocos 20
10.3Unity
10.4Unreal
10.5Java
10.6Node.js