Introduction to directplayDirectory: Creating and managing sessions Directplay Network Communication Directplay Transport Protocol Communicating with directplay objects Directplay lolobby support Body: Microsoft? Directplay? APIS provide developers with tools to develop multiplayer games or chat programs. A multiplayer game has two basic features: 1. Two or more independent users, each having a client game program 2. The network is connected to the user's computer (connected through the central computer server) Directplay provides an extra layer to separate the game from the underlying network layer. In addition, your game can easily use the directplay API and use directplay to manage network communication. The features provided by directplay make multiplayer games much simpler in development. Including: 1. create and manage point-to-point, client/service sessions) 2. Manage users and groups in one session) 3. Manage messages sent between members who have sessions on different network platforms 4. Make the game interact in the lobby 5. Enable voice Interaction This section (Introduction to directplay) provides a high-level overview of directplay functions. The subsequent sections will show you the details of directplay and how to use directplay in your game. Creating and managing sessions Game sessions are a special multiplayer game. In a session, two or more users are online at the same time, and each user has the same game client. A role (player) is an entity in a game and is customized by the game. Each user can have multiple roles. However, the game must manage these roles by itself and use the directplay interface object to manage these roles. The first step to create a session is to collect information about a group of users. There are two methods: 1. Most game sessions are managed by a loby application running on a remote computer. Most internet-based Games use this method. 2. Each user contacts each other. This method is generally used in a small LAN. And the game is not very big. After the session is managed, the game can be connected. During a session, the role may exit from the session or be added to a new role. In multiplayer games, the user UI in the same session should be synchronized. Managing multiplayer game sessions should repeatedly send message streams to each user. For example, each time a role moves, a message should be sent to update the role location on all other game clients. The core of directplay is to send efficient and secure messages to all computers in one session. There are two basic methods to organize session messages, one is point-to-point and the other is the customer/service mode. There is a lot of information about these two models, so I will not repeat them here. Directplay Network Communication The main function of directplay is to separate the game from the underlying network. If you want to send status update messages, you can call the directplay API without worrying about complex network connections. Directplay provides multiple network connections: TCP/IP, IPX, modem, and serial links. Directplay Transport Protocol The core of directplay is the directplay protocol. This transport layer protocol is completely rewritten in directplay8 and is now used in all messages. The directplay Protocol focuses on making it easy for you to send messages. The protocol provides many customized features for multiplayer games, including: 1. Reliable and unreliable message delivery. Reliable messages are sent continuously until the target program is sure to receive them. You can assign specific message sending methods according to your situation. 2. Continuous and non-continuous message transmission. Continuous messages are sent to the target program one by one. 3. Separate and package messages. When the message size exceeds the network permission, directplay Automatically splits and reassembles the package. 4. Blocking control. Directplay automatically controls the speed at which messages are sent, enabling the target program to execute and receive messages. 5. Sending order. To ensure that important messages are sent first, directplay can set the message sending level, including low, medium, and high priority. A high priority (highest priority) message is first sent to the front end of the message queue, followed by medium and low. 6. Message timeout processing. Prevent message queues from being blocked. directplay allows you to assign a timeout value for each message. When the message times out, it is removed from the message queue. Directplay addresses To send messages, each member of a multiplayer game must have a unique address. The computer running the game client provides the device address, while the game host provides the host address. The directplay address is a URL string. These strings are in the following format: X-directplay:/[data string] On different network connections, it contains elements such as the sender and receiver. The directplay address object generates a URL string. Depending on your proficiency, you can directly use the URL address or use the directplay address object to manage the URL. (Using the methods exposed by the address object to handle each element of the data string separately) Communicating with directplay objects Directplay is actually based on COM. Each component is managed in different aspects. For example, the directplay point (PEER) object (clsid_directplay8peer) is responsible for managing point-to-point games. You can communicate with the component through its interface. For example, in point-to-point games, idirectplay8peer: sendto is used when you send data to another user. Directplay sends a message to the target. Directplay uses many callback functions (callback functions) to contact each other. In principle, these functions are the same as the callback functions used by Windows programs. The game executes these callback functions and transfers function pointers during directplay initialization. When directplay needs to communicate, it calls the callback function and transmits two important information: 1. Identify the message category ID. 2. A data block pointer, usually a struct. For example, when a message is sent to the target, the callback function of the Target Program receives the dpnmsgid_receive Message ID, indicating that the message has arrived. It is accompanied by a structure containing data. Because most directplay messages are multi-threaded, the key is how the callback function is properly executed. Directplay lolobby support The main task in the lobby is to arrange role meetings and games. Lobby servers generally have other functions, such as hosting chat rooms, sending news and information, and hosting business transactions. The lobby server facilitates the use and scheduling of multiplayer games, but it is not necessary. Multiplayer games can also communicate directly between lobby clients ). A multiplayer game with a hall is composed of three parts: 1 Hall Server 2 Hall Client 3. A lobbyable game) Directplay does not specifically tell the hall server how to work, you can arrange it by yourself. Directplay provides support for hall clients. A hall client works through the hall server Connection Program (vendor), and the connection program is installed on the user's system. It is like a chain to connect users and the hall. When you want to communicate directly, you must know the work details of each hall. The communication details of the hall client game receiving Hall server, using the appropriate communication protocol. The lobby client communicates with the game program. Games can also use interfaces to send messages to lobby clients. The hall can actually connect to any program. However, the game must have some specific lobby support components (lolobby-aware components ). Generally, a game in the support hall can communicate with the lobby client through sessions. If the game is registered as a support Hall, the lobby client can automatically receive updates and update the information in the game. Such as host migration. |