• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天行健 君子當(dāng)自強(qiáng)而不息

            Getting Online with Multiplayer Gaming(6)

             

            Looking at the Server

            The game server is a specialized piece of software. It doesn’t need fancy graphics, kicking tunes, or even dedicated input functions. The server merely needs to process the actions received from connected
            players and, every so often, send updates to the clients.

            Once the server begins executing, it enters into a tight loop, continuously processing
            incoming network messages, updating all connected players based on their last
            known movement actions, and sending updates.

            Few network messages are received from the server—connection requests, disconnect
            notifications, and player actions. Those player actions are solely up to the
            game design, and with the demo game for this chapter, those actions include
            only players walking, standing still, or attacking with a weapon.

            As network messages are received from clients, the messages are stuffed into a
            message queue. Using a message queue
            speeds up network operations and leaves the majority of the work up to the main
            application (rather than the network code thread). The server maintains a message
            queue (a stack of messages) that holds all incoming messages. As a message comes
            in, it is added to the queue. The server continuously pulls out the oldest message
            and sends it off to various functions for processing. This process of message handling
            is illustrated in Figure 19.7.

            NOTE
            To keep things processing quickly, the server updates players only
            every 33ms, whereas client updates are sent approximately every
            100ms. Incoming messages (contained in the message queue) are
            processed every frame, however.

            The server deals with player connection requests by first checking whether there are
            any open slots for players. If so, the player data is requested from the client and saved
            in a local structure. All players in the game are notified that another player has
            joined the fray, and play goes on. A slot is freed up whenever a player disconnects.

            Player actions are quickly dealt with; all player actions simply change the state of
            the player. At this point, the only states used are those for walking, standing still,
            attacking, and being hurt. At every frame, those states are used to update the
            player. As player actions are received, the server sends them out to all other connected
            players so that the players can update their game states (between server
            updates, of course).

            Aside from dealing with network messages, the server updates the state of the
            players. If a player character’s last known state was walking in a certain direction,
            that player’s character continues to walk in that direction. The server, in all its
            authority, will perform collision detection to make sure those moving characters
            can’t walk through walls!

            NOTE
            By allowing only the server to update the game world, you eliminate
            cheaters (players who try to alter the game-play to their advantage).
            Cheaters typically work by sending bogus data to the server in
            the hope that they can move their player in impossible ways.

            For every action and state you add to your game, you add the logic to the server to
            process the characters. For example, the attack state requires the server to refuse
            further state changes from a player until the attack state has cleared (after one second).
            At the same time the attack is initiated by a client, the server will calculate
            which other clients were hit and the level of damage.

            Implementing the server is easy. After you create a sound base from which to
            work, you can easily begin adding more features to the server. Besides adding
            new actions that players can perform, you can also add features such as player
            account management. However, now it's time to take a quick peek at the client
            side of things.

            posted on 2007-12-18 17:48 lovedday 閱讀(148) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            公告

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關(guān)鏈接

            搜索

            最新評論

            国产精品久久久久影院色| 国产精品美女久久久久av爽| 精品久久亚洲中文无码| 国产∨亚洲V天堂无码久久久| 97久久综合精品久久久综合| 久久人妻少妇嫩草AV无码蜜桃| 久久99久国产麻精品66| 26uuu久久五月天| 久久99久国产麻精品66| 久久乐国产精品亚洲综合| 久久免费的精品国产V∧| 久久亚洲精品国产精品婷婷| 青青青青久久精品国产h| 国产色综合久久无码有码| 久久久久久国产a免费观看不卡 | 久久综合综合久久综合| 久久久综合香蕉尹人综合网| 久久久久一区二区三区| 国内精品久久久久久99| 欧美激情精品久久久久久久九九九| 久久精品视频91| 国产成人综合久久精品尤物| 日韩AV毛片精品久久久| 免费一级做a爰片久久毛片潮| 国内精品久久久久| 亚洲精品成人久久久| 久久er国产精品免费观看8| 久久久久综合国产欧美一区二区 | 国产亚洲精久久久久久无码AV| 色婷婷综合久久久中文字幕| 亚洲欧美久久久久9999 | 久久亚洲精品国产精品婷婷| segui久久国产精品| 久久香蕉国产线看观看乱码| 国产精品美女久久久久| 久久精品中文字幕无码绿巨人| 久久久久亚洲精品日久生情| 一本一本久久a久久综合精品蜜桃| 久久人与动人物a级毛片| 久久国产色av免费看| 久久99精品久久久久子伦|