6.Sample code for Distributed Lobby System

Sample code for Distributed Lobby System is a sample online game program.

Features

Sample codes for Distributed Lobby System are as followed.

How to run Sample code for Distributed Lobby System is guided in 6.1 How to use Casual Game Sample

The server structure of Sample code for Distributed Lobby System is explained in Distributed server of sample casual game 2.

Sample code for Distributed Lobby System has a vast amount of source codes (annotations alone exceed 8000 line). Thus it is recommended to refer on API reference of sample codes for better understanding.

In case the samples of casual game system guided in Sample code for Distributed Lobby System are not suitable with the project you are developing, we recommend you build your game from scratch as just referring to Sample code for Distributed Lobby System.

Of course you can develop a casual game by editing Sample code for Distributed Lobby System but this would be very troublesome when updates take place in ProudNet and you end up searching for the update contents every single time. Therefore, it has suggested to branch out your source using your Source Control.

The practical use of functions guided in Sample code for Distributed Lobby System are as followed.

6.1How to use Casual Game Sample

First, install Creating a sample database

Next, run the server program.

m_dbmsConnectionString = L"Data Source=localhost;Database=ProudDB2-Test;Trusted_Connection=yes";

Tip : If you are using the MYSQL, please see 'Sample/ SimpleAdoMysql'

Now, let's run the client program.

When the client is running, you can create a new playable character or delete an existing character. When your character is selected, click on [Confirm] to select a lobby channel you wish to join.

When a lobby channel is selected, it will show a lobby screen with functionalities of “chat to all”, “create a session”, “join a session”, or “go back to the previous screen”. After creating a session, you can join a game session where you can wait for other players to join or start the game as-is. In order to start the game, every player in the game session must set for [Ready!].

You can control this sample program very easily. You can control your character with arrows and space-bar and get item avoiding bullets on the screen. Blue bullet is moving at the bottom and red is top. You can avoid it with space-bar. Once your character’s point become 0, you will kicked out to lobby and point will reset to 10.

The scores earned by each player get stored in the game database and they will be displayed next to the character's name with [ ] on the game screen.

6.2Distributed server of sample casual game 2

The server inside Sample code for Distributed Lobby System is carefully constructed in deep consideration of scalability in the commercial casual game. And in result, it is distributed as followed.

그림 6-1Structure diagram of sample casual game 2

6.3The relationship between server and client in the game server

At Sample code for Distributed Lobby System, each game server gets distributed by its functionality and communicates between servers. Please refer to 6.2 Distributed server of sample casual game 2 for more details.

When the farm client begins, it attempts to connect to the farm server.

•CFarmClient.Connect

•CFarmServer.OnClientJoin

•CFarmClient.OnJoinServerComplete

When it is successfully connected, the farm starts the authentication procedure.

•CFarmServer.RequestFarmLogon

•CFarmClient.NotifyFarmLogonSuccess

When the authentication is completed, the farm client waits until it gets disconnected from the farm server.

•CFarmClient.OnLeaveServer

•CFarmServer.OnClientLeave

The farm clients are each linked with peer-to-peer communication. So the communication between the lobby server and battle server can persistently occur.

6.4Entry server and client

When game client of Sample code for Distributed Lobby System is running first time, it will create entry client. Then entry client connect to entry server.

•CEntryClient::Connect

•CEntryClient::OnJoinServerComplete

Once logon process is finished, entry client will request registering to entry server or sending encrypted ID and Password as message to logon. Entry server request load information and authenticate gamer to ProudDB cache server that based on collected information.

Logon after registering

•CEntryServer::RequestLoadNewGamer

•CEntryClient::NotifyLoadNewGamerSuccess

•CEntryServer::RequestFirstLogon

•CEntryClient::NotifyFirstLogonSuccess

Logon with current ID

•CEntryServer::RequestFirstLogon

•CEntryClient::NotifyFirstLogonSuccess

Once it succeed gamer authentication and information loading, game client will transform to selecting character form. And it will request local player character list to entry server then receive it.

•CEntryServer::RequestHeroSlots

•CEntryClient::Hero_Begin

•CEntryClient::Hero_Add

•CEntryClient::Hero_End

In this stage, gamer can create or delete local player character. And choose player character. Then entry server will save selected character information to gamer database.

•CEntryServer::RequestAddHero

•CEntryClient::NotifyAddHeroSuccess

•CEntryServer::RequestRemoveHero

•CEntryServer::NotifyRemoveHeroSuccess

•CEntryServer::RequestSelectHero

•CEntryServer::NotifySelectHeroSuccess

Then entry client request lobby channel list to server. Lobby channel list that assigned from entry server contains name of each lobby server, number of concurrent users, and internet address of lobby server. Game client will show list to gamer then gamer can choose one of those.

•CEntryServer::RequestLobbyList

•CEntryClient::LobbyList_Begin

•CEntryClient::LobbyList_Add

•CEntryClient::LobbyList_End

During this process farm client (lobby server at this stage) request exclusive right to farm server. Entry client will be disconnected and removed. Game client will prepare lobby client then try to connect to lobby server. Please refer to 6.5 Lobby Server and Client.

There are possibly occurring problem which is requesting exclusive right when connecting with same ID and Password by DBCache Client of other entry client. After processing of this thing will prevent dividing customfield in parameter that coming from OnDataUnloadRequested callback. In casual game sample2, it will pass exclusive right to newest farm client that requested exclusive right.

6.5Lobby Server and Client

When the connection is successfully made between the lobby client and the lobby server by 6.4 Entry server and client, the game client shows the lobby screen.

•CLobbyClient.Connect

•CLobbyServer.OnClientJoin

•CLobbyClient.OnJoinServerComplete

•CLobbyServer.RequestNextLogon

•CLobbyClient.NotifyNextLogonSuccess

When the data loading for the lobby screen is done, it displays the list of all players, chatting window, and game sessions.

•CLobbyServer.NotifyChannelFormReady

The list of players in the lobby can be expanded, edited and deleted at all time. Such changes in information can be persistently received from the lobby server.

•CLobbyClient.HeroSlot_Appear

•CLobbyClient.HeroSlot_Disappear

The list of game sessions in the lobby can be expanded, edited and deleted at all time. Such changes in information can be persistently received from the lobby server.

•CLobbyClient.GameRoom_Appear

•CLobbyClient.GameRoom_ShowState

•CLobbyClient.GameRoom_Disappear

The actual game session exists in the battle server. The lobby server only acts out a role of sending the list of game sessions synchronized with the battle server to the lobby client.

•CFarmClient.GameRoom_Appear

•CLobbyServer.OnGameRoomAppear

•CFarmClient.GameRoom_ShowState

•CLobbyServer.OnGameRoomShowState

•CFarmClient.GameRoom_Disappear

•CLobbyServer.OnGameRoomDisappear

When a chatting message is sent from a lobby client to the lobby server, it Multicast the chatting message to other lobby clients connected to the server. And, the chatting message that each client received gets displayed in the chatting window.

•CLobbyServer.Chat

•CLobbyClient.ShowChat

Creating a game session

그림 6-2Sequence Diagram for Game Session Creation

When player requests to create a game session, such request get passed on to the lobby server. Then the lobby server starts searching for the least crowded battle server subordinated to the lobby server and requests to create a session there.

•CLobbyServer.RequestCreateGameRoom

•CFarmClient.RequestCreateGameRoom

•CBattleServer.CreateGameRoomByLobbyServer

The battle server manages the request of a game session creation and sends its result the lobby server. Then the lobby server sends the received information to the lobby client.

•CFarmClient.NotifyCreateGameRoomResult

•CLobbyServer.OnCreateGameRoomResult

•CLobbyClient.NotifyCreateRoomSuccess

Joining a game session

그림 6-3Sequence Diagram for joining a game session

When player requests to join one of already existing game sessions, the lobby client sends the requesting message to the lobby server. Upon receiving such request, the lobby server requests an entry permission to the battle server that contains the game session player selected.

•CLobbyServer.RequestJoinGameRoom

•CFarmClient.RequestJoinGameRoom

When the battle server receives the request of entry permission, it first judges the entry conditions of player then sends the result to the lobby server. Upon receiving the result, the lobby server delivers “success” or “fail” message to the lobby client.

•CBattleServer.JoinGameRoomByLobbyServer

•CFarmClient.NotifyJoinGameRoomResult

•CLobbyClient.NotifyJoinRoomSuccess

When the lobby client receives “success” message for creating or joining a game session, the client also receives the address of battle server and guid of the game session. At this time, the lobby client gets terminated and starts connecting to the battle server after the battle client are created. This process is explained in battle_session. In this process, there are possibly occurring problem which is requesting exclusive right when connecting with same ID and Password by DBCache Client of other entry client. However it can be solved by passing exclusive right to newest farm client that requested exclusive right.

6.6Battle Server and Client

After the battle client goes through the process of lobby_session and starts connecting to the battle server, it waits until the connection is successfully made with the battle server.

•CBattleClient.Connect

•CBattleServer.OnClientJoin

•CBattleClient.OnJoinServerComplete

When the connection is made, then the battle server starts the logon protocol and receives the information of game session that player wishes to join. This means that the process of joining to the game session gets concurrently conducted at the logon protocol.

•CBattleServer.RequestNextLogon

•CBattleClient.NotifyNextLogonSuccess

When logging on(as well as joining the game session) to the battle server is successfully completed, the game client displays the session waiting room screen, which receives the list of players and information of game session itself.

•CBattleClient.NotifyGameRoomInfo

•CBattleClient.HeroSlot_Appear

•CBattleClient.HeroSlot_Disappear

•CBattleClient.HeroSlot_ShowState

If local player is the host, then he or she can request to start a game.

•CBattleServer.RequestStartPlayMode

Other players than the host must all agree to start the game by clicking on ‘Ready' from the session screen.

•CBattleServer.RequestToggleBattleReady

When every player in the game session sets for ready, the host can start the game immediately. But in order for the game to start, all required data files must be loaded for each game client and until then all players must be on standby.

•CBattleClient.GotoLoadingMode

•CBattleServer.NotifyLoadFinished

•CBattleClient.GotoPlayMode

When the score of players is changed during in-game play, it is necessary to be stored in the database server. This sample allows player to earn a score quickly, which gets stored in the database server.

•CBattleServer.RequestGainScore

When player exits during in-game play, all it needs is to disconnect the player from the battle server and sends the player back to the lobby server logon screen. On the other hand, when the game is over (i.e. Mission Cleared), the game session must go back to the waiting mode and display the screen of session waiting room to each player. For learning purpose, this sample allows you to clear a mission rapidly and witness the process of game ending. Also if other DBcache client of entry client request exclusive right, just disconnect current connection and pass exclusive right.

•CBattleServer.RequestMissionClear

•CBattleServer.GameRoom_GotoWaitingMode

•CBattleClient.GotoWaitingMode