Results 1 to 9 of 9

Thread: Multiplayer Networking

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2022
    Posts
    6

    Multiplayer Networking

    Hi All,

    I have been a relatively long term user of VB6/A/script as it is used heavily in the industry I work in.
    I thought a good learning experience from what I normally do with the language would be to make an attempt at writing a simple video game (2D tick based RPG).
    So far I have some basic tools built for creating a map, navigation (A*, which was actually quite fun to write), rendering, game loop etc. But what is really stumping or perhaps just hindering me at the moment is how to get the networking portion built in.

    I have envisaged that I would like to have up to 5 players (Host + 4 clients). Now I have used winsock controls successfully before, but what I am struggling with is conceptualizing how to share things like the world state, or the information stored in each character/item/maps class. I have thought about maybe I just send the entire class over the winsock (which for the moment I have only figured out how to do by writing it to a binary file... which I would rather not have any IO operations), or maybe I just send enough information for each client to update its own records.

    I don't really want to proceed much further until I have this all figured out as I would prefer to design the game around how the networking works before rather than tack it on at the end and have to extensively modify the game logic. If anyone can point me in the right direction, that would be greatly appreciated.

    Cheers.

  2. #2
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,731

    Re: Multiplayer Networking

    I would do:
    - when client handshake to host, host will ask for basic info and send that to all players and send back to client about the current players.
    - all clients connect to each other.
    - when player do something. like walking, levelup, change state (what kind of action, if idle mode, fight mode, interaction with player etc) it will send that to everyone.
    - when player interact to another player, they share information needed for that session.

    not sure there need to be that much info. its mostly x/y/z and map-location, character-parameter, name, level, stats and of course IP/PORT of each other.
    if u want players to see each other inventory, u send that as well. if its only when interaction between two, just send it then.

    for me RPG is that u walk around killing stuff, collect stuff, do quests etc.
    and another player should see other players like any other NPC/monster/object. and not until they start talking/fighting that more info are needed to share,
    otherwise they just see a character walking around with a name-tag and/or possibly a small info-panel with name/level/stats.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2022
    Posts
    6

    Re: Multiplayer Networking

    Thanks,

    I think the biggest thing I am struggling with right now is figuring out how to share a variable over the network without using IO operations. For example I would like to send the data contained in the variable for a randomly generated map which in this case is a multidimensional array. How would I convert that to a byte array so the winsock can actually send it and then reassemble it back at the client side.... all the examples for winsock I can find either use IO or only ever talk about strings.

  4. #4
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,731

    Re: Multiplayer Networking

    I use wsock32 API calls.
    stopped using the built-in one years ago.
    anyway, wsock32 API is all bytes.
    and if I remember correctly. I use to send and receive files,
    so u need to declare what kind of structure u want to receive. I think u can pick string and bytes array.

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2022
    Posts
    6

    Re: Multiplayer Networking

    Thanks for your input,

    Do you have any insight or know of any resources that would help me pack the contents of a variable into a byte array and then unpack it back into the original variable, I can only find examples that deal with strings (like simple chat programs) I can already do that.

  6. #6
    The Idiot
    Join Date
    Dec 2014
    Posts
    2,731

    Re: Multiplayer Networking

    when I save to disk I convert my UDT into byte array.
    example

    ReDim Data(Memory) As Byte (I free up enough memory so it will not go out of bound, I Redim Preserve later if the size is lower)
    Pos = 0
    - Here I Create A Loop (if array) and go through all the UDT I have
    - Examples:
    AddByte Somethingwithbytes
    AddInteger SomethingwithInteger
    AddString SomethingwithString

    so its a bit of work to create the "Data" Array
    and the same when "Loading/Unpacking"

    Somethingwithbytes = GetByte

    the functions are quite easy example:

    Code:
    Private Function GetByte() As Byte
        GetByte = Data(Pos)
        Pos = Pos + 1
    End Function
    Code:
    Private Sub AddString(SourceString As String)
        Dim bArray() As Byte, tbyte As Byte
        
        If SourceString = vbNullString Then
            tbyte = 0
            AddByte tbyte
        Else
            bArray = StrConv(SourceString, vbFromUnicode)
            tbyte = UBound(bArray) + 1
            AddByte tbyte
            CopyMemory Data(Pos), bArray(0), tbyte
            Pos = Pos + tbyte
        End If
    End Sub

  7. #7
    Junior Member
    Join Date
    Nov 2021
    Posts
    18

    Re: Multiplayer Networking

    Quote Originally Posted by baka View Post
    - all clients connect to each other.
    I'd strongly suggest using a traditional client/server model, where the server relays information, because:
    - No need to worry about NAT/Firewall on the clients
    - Much easier to synchronize state, as the host is the one deciding what's the truth

    Only downside would be slightly increased latency between clients as they go through the host

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2022
    Posts
    6

    Re: Multiplayer Networking

    Thanks baka, I'll give it a whirl when a get a couple or hours spare... will let you know if I have any more questions.




    Zahl, yeah I agree. It is just going to be a simple point and click (Like Runescape) so I am planning to use a similar networking model where game logic is evaluated in gameticks (about 600ms). So each connected client needs to have the actions for the next gametick submitted to the server early enough to get a response for the next upcoming tick (TickLength - Ping - SendPadding - ReceivePadding), and I am thinking of selecting the highest ping time client (up to a certain point) to defer actions on the host and other clients to the next gametick (an attempt to keep things even).

    I am planning to use UDP for this, still a little iffy about it as the delivery of messages is not guaranteed however, but TCP may introduce unacceptable latency.

  9. #9
    New Member
    Join Date
    Dec 2022
    Posts
    1

    Re: Multiplayer Networking

    I looked at a similar problem on YouTube and found some answers! And I found the answer here too!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width