Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Online multiplayer turn-based game with UDP — Gideros Forum

Online multiplayer turn-based game with UDP

RickyngkRickyngk Member
edited March 2013 in General questions
Hi,

I'd like to make a Online multiplayer turn-based game (such as play chess). I decide to use UDP.

For client discovery, I use UDP punch hole technique http://www.brynosaurus.com/pub/net/p2pnat/

For turn-based controlling, I use the following mechanism:
+ Suppose that a host place two roles: host and client too
+ Client works in 3 state: LOCK (not in turn), INPUT (in turn), and SYNC (submit data to server), with two important properties: seq (sequence index), and turnIndex (turn index of each client)
+ Server send update data to clients frequently. Data include two important properties: seq (sequence index) and turnIndex (notice which client is in turn)


Client state diagram: https://sites.google.com/site/sbskit/papers/online-multiplayer-turn-based-game-with-udp/client_state.png?attredirects=0

Host flow:
seqNo = 0
userInTurn = 0
while (true)
    if receive_submit() then
        seqNo = seqNo  + 1
        userInTurn = get_next_turn()
    end
    update_game_logic()
    deliver_to_all_clients(seqNo, userInTurn, gamedata)
end
Client flow:
seqNo = -1
function On_Receive_Data_Update(ServerSeqNo, currentTurnIndex, gamedata)
    if ServerSeqNo >= seqNo then -- valid seq
        if ServerSeqNo > seqNo -- change state
            if state is LOCK then
                if currentTurnIndex == turnIndex then
                    switch_to_state(INPUT)
                end
            elseif state is INPUT then
                if currentTurnIndex != turnIndex then
                    switch_to_state(LOCK)
                end
           else
                if currentTurnIndex == turnIndex then
                    switch_to_state(INPUT)
                else
                    switch_to_state(LOCK)
                end
           end
        end
 
        update_game_with_data(gamedata)
    end
end
 
function update_client_control()
    if state is INPUT then
       update_game_input()
       if hasEndTurn() then submit() end
    end
end
See diagram in attachment

Would you please give me your idea about my work. Any mistakes, problems, and your suggestion.

Thank you in advance!
+1 -1 (+1 / -0 )Share on Facebook

Comments

  • atilimatilim Maintainer
    edited March 2013
    @Rickyngk I have little information about this issue. But afaik, UDP hole punching is really hard to implement. And your clients needs a common server to pass through NAT and hole punch between them. Isn't it easier and more stable to use a server to orchestrate all network communication instead of hole punching?

    I think hole punching is (only) useful when you need to send large amount of data (such as file transfer or audio/video communication) between clients. Otherwise, communication through a server is preferable.
  • gorkemgorkem Maintainer
    @Rickyngk how frequent are you sending data? can push notifications be an option?
  • RickyngkRickyngk Member
    edited March 2013
    @atilim: I don't use server as a centralize system, and give host-role for client because of some reasons:
    + I wanna keep server in low CPU (discovery & forward only) so could increase CCU
    + If one server is not enough, I can use another one easily (they take role as client discovery and message forwarder at not, not game logic)
    + developer can develop game in client, no need server code (for simple game)
    + udp (or tcp) punch keeps traffic transfer thought server down

    Is it weird ? :D

    @gorkem: I send one data package per second.
    About push notification, you means local or remote notification? I don't know how does it work in this case :D
  • atilimatilim Maintainer
    edited March 2013
    @Rickyngk I think the main problem is that UDP hole punching is extremely hard to implement correctly. Therefore even for realtime MMO games, it's not used (or I haven't seen a real world example).

    not weird but insane :)

    Centralized systems also have some advantages like:
    - it's easy to modify game logic
    - it's hard to cheat
  • gorkemgorkem Maintainer
    @Rickyngk I meant (remote) push notifications. Yours can be a good example to benefit from push.
Sign In or Register to comment.