Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Net message tutoring required

Author
Message
Person6
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Canada, Eh?
Posted: 20th Nov 2011 08:00
I apologize for not searching in-depth for this topic before posting, but how exactly can I search for my exact question.

I am wondering about Net Messages, I'm trying to make a multiplayer game that has a server running, and 8 clients attached. But it's really confusing me how, all I have to do, is send a net message and receive it, but I don't understand how the server can determine what message it's looking at, whether it's looking at the integer message that contains my X value, or the message that contains my bullet's Y value?
Is there some form of net message tag system I'm not aware of? such as labeling them in the same way we label objects?

Please help, I can't continue till I figure this out.
Thanks

solo Game Dev
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 20th Nov 2011 12:33
You simply send some more bytes telling the packet (message) type

Ie.



"Why do programmers get Halloween and Christmas mixed up?"
Person6
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Canada, Eh?
Posted: 20th Nov 2011 21:48
How exactly do the bytes work?

solo Game Dev
Darkzombies
13
Years of Service
User Offline
Joined: 25th Dec 2010
Location: In multiple tabs, most likely youtube.
Posted: 20th Nov 2011 22:20
they go from 0 - 255, that's all I know though lol.

-------------------------------------------------------------
Person6
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Canada, Eh?
Posted: 20th Nov 2011 22:27
I appreciate the help, but I still don't know it's definition, what data does it hold other than a size number from 0-255.
I know it has something to do with memblocks, but I just don't get it.

solo Game Dev
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Nov 2011 22:52
Each value means what you decide it means - it's all a chunk of data that represents the information you want to transfer.

You might decide that a type value of 0 is position information, a type value of 1 is an item status change (ie it's been picked up, or has been respawned) - it's basically up to you.

When you set the type, you also provide the relevant information for that type.

For example, you may have the following information for positions:


Item status change might have the following information:


So determine what information types you want to transfer, then work out the data required for each information type, then write the code to assemble and/or decipher that information within your client & server programs.

Person6
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Canada, Eh?
Posted: 21st Nov 2011 21:42
Okay, I'm starting to get it, but I still don't understand the way you guys are displaying this,
Offset Data type Data
0 WORD Packet type = always zero
What's with the offset? I see that nowhere.

And also, to get another question out of the way at the same time, I have 2 exe's for my program, one is the client, the other the server, I use this code to determine when a player joins, and when they leave, and it also assigns them a player number when they join, from 1-8, but every player that joins ends up becoming player 1, help?

I know for certain that the players are in fact connecting and receiving a number, because if they don't, then it doesn't load crucial objects 11-19, so far I can only distinguish the problem as everyone receiving the same number.

solo Game Dev
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 22nd Nov 2011 14:38
Quote: "What's with the offset? I see that nowhere."

Because once we get beyond toy applications, we switch to sending memblocks to and fro.

You'll soon see that there's only so much you can do with integers or floats on their own - sending a float, how do you know what player it's for, or what it represents (position x, y, z or rotation x, y, z or speed or many other things).

Quote: "but every player that joins ends up becoming player 1, help?"

Sending a message to player 0 sends the message to everyone except for the sender.

EricB
12
Years of Service
User Offline
Joined: 3rd Nov 2011
Location:
Posted: 22nd Nov 2011 14:45
If I understand you correctly your question is "how do I know what the offset is?".

As IanM stated before you create the offset with a definition of your data type.

An OFFSET if simply the number of bits from the beginning of the data type until the particular information you are interested in occurs.

Imagine this 32 bit sequence of ones and zeroes as your message to the server:

0x0010110101010011101101101011100

The first "00" could denote that this is a positional data packet and not a "player message" packet or a "weapon firing solution" packet which would change the type. The next four spaces of 1011 could denote player ID and Team ID. The next 26 bits could denote X,Y,Z positional data in single bytes of 0-255 and a two bit checksum.

You as the programmer create this data which then is sent via the DBP network calls and then layered into a UDP or TCP datagram by the OS and sent down the pipe.

You do not even have to resolve to this level of detail if you use a type as IanM suggested you will only need to know the position of the data within the type.

As to the question regarding the code snippet I will leave that to someone with more experience with the network side of things within DBP.
Person6
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Canada, Eh?
Posted: 23rd Nov 2011 19:38
Thanks, that gives me a little bit more of an understanding, but I think I'll have to play around with it a bit to understand it fully.

And as for my other problem,
Quote: "
Quote: "but every player that joins ends up becoming player 1, help?""
Quote: "
Sending a message to player 0 sends the message to everyone except for the sender."


I tried sending it to player one before, and that didn't work, but I just remembered that I was trying to send to player 1 before, but player 1 is the server.

But, my problem persists with my variable LPC#, which is Last Player Created. I set
LPC# = Net Player Created
Shouldn't that make LPC# the player number of the last player joined?

solo Game Dev
EricB
12
Years of Service
User Offline
Joined: 3rd Nov 2011
Location:
Posted: 23rd Nov 2011 22:14
I have taken a second look at your code. According to the documentation net player created () returns an integer not a float. As I'm not that familiar with DBP I am not entirely sure if this is the problem or not. You are placing an integer into a float which looks like this: 1 (as an integer) becomes 1.0 (as a float) which is not logically equal to 1 within the IF statements you have written.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Nov 2011 19:03
I'm not sure how we can really help, because you've not provided any runnable code for us to check.

So, here's some very dirty code I wrote some years ago that you can use to see that player numbers do work, and work correctly:


Run 3 copies of the code, 1 as server, and 2 as client - start the server first. As each client connects or disconnects, you'll see that it's reported correctly in the server.

Person6
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Canada, Eh?
Posted: 24th Nov 2011 20:53


It seems to make sense mostly, but if you check if old/new is greater than 0, but don't set it back to zero, does that mean the command does it automatically?
So upon a new player joining I have to get that info immediately?
Cause if so that both seems odd yet explains why my program doesn't work.

solo Game Dev
Person6
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Canada, Eh?
Posted: 24th Nov 2011 21:13 Edited at: 24th Nov 2011 22:32
Sorry, my account is still new so my other message hasn't shown up yet.

Thank you guys so much both IanM and EricB, I did get it working, and now the players each receive their own player number properly and are represented by their own character...

But, if one of you could give me a small sample code of sending coordinates from a client, to a server, then back to the other clients, that would be appreciated. (because obviously trial and error only got me so far before) XD

Solo Game Dev
DBPro User
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Nov 2011 23:20
Quote: "does that mean the command does it automatically?"

The NET PLAYER CREATED and NET PLAYER DELETED functions will return each connected/disconnected player number only once - the next time you call these functions, DBPro will either return 0, or the number of the next player that connected/disconnected.

As for the variable being reset... well, no it's ALWAYS set to the value that the function returns. You don't need to clear it or pre-prepare it.

Here's another example I've dug up:


Run two sessions. The active application will send the mouse coordinates to the other. As it's a very simple example, there are only two message types. The first is the x/y of the mouse. The last is the x/y of the mouse, plus the mouse button state.

The format of these is as follows...


As I said, it's not a very complex system (and wasn't meant to be - I was learning the multiplayer commands myself at the time), so the message types aren't very complex.

Person6
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Canada, Eh?
Posted: 25th Nov 2011 00:21
Quote: "The NET PLAYER CREATED and NET PLAYER DELETED functions will return each connected/disconnected player number only once - the next time you call these functions, DBPro will either return 0, or the number of the next player that connected/disconnected."

Thanks, that's good to know.

As for the memblock thing, if I'm understanding this correctly, you create a memblock by using the write memblock dword command, and you can write up to 255 different types of info into one memblock using partitions of bytes within it. You then read the memblock and the corresponding offset number with the reciever?

And also, can the offset be any number from 0-255? because in all of your examples you guys use only even numbers, and they seem to all be doubles, ex. 2 4 8, please explain.

Solo Game Dev
DBPro User
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Nov 2011 14:31
Um, no.

Memblocks are numbered from 1 to 255, but can be any size that fits into memory - they are basically just a chunk of memory that you have to impose an order upon. The offset we mentioned is the offset into the memblock itself.

The command 'NET MESSAGE MEMBLOCK 1' takes the incoming message and creates memblock number 1. The code then looks at the first DWORD of this memblock (offset 0) to see what data it contains: 'SELECT MEMBLOCK DWORD(1, 0)'.

When sending data, the first thing to do is to create the memblock ('MAKE MEMBLOCK 1, 12' - memblock 1, size 12 bytes), then to set it's type ('WRITE MEMBLOCK DWORD 1, 0, 0').

Person6
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Canada, Eh?
Posted: 26th Nov 2011 06:14
okay...... it's making a little more sense... but I still don't entirely get it.
Could I ask that you explain it as you would if you were talking to someone who knew absolutely nothing about DBPro?

Solo Game Dev
DBPro User
EricB
12
Years of Service
User Offline
Joined: 3rd Nov 2011
Location:
Posted: 28th Nov 2011 14:05
A MEM BLOCK is a memory block or a segment of memory reserved by the program to use. As IanM noted above it can be any size you can create up to the maximum amount of memory available in a given system. When a MEM BLOCK is created with the MAKE MEMBLOCK command the first parameter is the memblock number then the size in bytes (8 bits per byte). The next portion of his example sets the type of data contained in the memblock by writing at offset 0 the data of 0. This is his usage you could write 16 in the same location and use 16 as your identifer for data type. This could actually be much more complicated as offset 0 is a DWORD long which is a rather large. Once the memblock is created and it's type is written any data that will fit can be written to the memblock. Once the memblock has all needed and required data written to it it may be sent to any or all receiving hosts with the SEND NET MESSAGE MEMBLOCK command.

If you are having trouble understanding these examples perhaps you should try working on the tutorials in the tutorials http://forum.thegamecreators.com/?m=forum_view&t=115633&b=7 thread. I'm not trying to seem condescending as I have asked a few noobish questions myself. It's just that most of what you are asking I have answered by reading the tutorial threads or using the built in help. After working on the tutorials if you have specific questions regarding examples or why something behaves in some manner I will answer to the best if my ability.
Person6
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Canada, Eh?
Posted: 29th Nov 2011 20:40
How do I know how much size any data requires? How do I know how big to make the memblock?

Solo Game Dev
DBPro User
Person6
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Canada, Eh?
Posted: 29th Nov 2011 20:45
Sorry, other message hasn't shown up yet...

EricB: I already read lots of those tutorials, in fact, I read them right before posting here in the first place, they lacked the info I needed.

And just for clarification purposes, what is the exact definition of DWORD?

Solo Game Dev
DBPro User
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 29th Nov 2011 21:06
A quick question Person6, is your game to be played on a Local Area Network (LAN) or over the internet?

I think DBPro's network commands are for LAN only, but there are plugins that works over the internet

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
Person6
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Canada, Eh?
Posted: 30th Nov 2011 02:28
My game is LAN

Okay, I've got it mostly, but I'm getting errors with the commands here...

It tells me "Memblock position out of range"

Solo Game Dev
DBPro User
EricB
12
Years of Service
User Offline
Joined: 3rd Nov 2011
Location:
Posted: 30th Nov 2011 13:25
Quote: "Make Memblock 1,4 Write Memblock Dword 1,1,1 Write Memblock float 1,2,pIX# Write Memblock float 1,3,pIY# Write Memblock float 1,4,pIZ# "


You made a Memblock 4 bytes or 32 bits long then you put a Dword into the first position which is 4 bytes or 32 bits long. Do you see where you went wrong now?

I strongly suggest that you do some tutorials to better understand how long various built in data types are and what the difference between floats and ints is. I suspect that you don't mean to use a float to describe a player position. in x,y,z format.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 3rd Dec 2011 21:23
Quote: "How do I know how much size any data requires?"

You decide what data needs to be exchanged in each message type, and how that data is represented.

For instance, position is usually represented in 3D with 3 float values - each float is 4 bytes in size, so you need to have 12 bytes of space in your memblock for the position.

Another example is the message type - you may have only a small number of message types (ie, less than 256 types). Numbers from 0 to 255 can be represented with a single byte value.

Using the above:


Note that the numbering when accessing memblock data is from 0, not from 1. It's the offset from the very first byte of data within the memblock.

Here are the sizes of each item you can write to the memblock:
boolean/byte = 1 byte
word = 2 bytes
integer/float/dword = 4 bytes

Login to post a reply

Server time is: 2024-05-20 04:55:29
Your offset time is: 2024-05-20 04:55:29