Server > Unique Client - [Help]

Posted By: indiGLOW

Server > Unique Client - [Help] - 08/18/08 20:41

I am having some difficulty using 'SEND_STRING_TO', mostly it appears to be establishing correct pointers/handles when entities are created. i.e player1 = client1, player2 = client2, etc...

I am trying to create a server side array of all currently connected players, pointers to each players master entity, and use this to send strings to individual clients.

Setting up this part of MP is really busting my brain, and after 2 weeks of trying to crack it, I am out of ideas...

Please could someone demonstrate how I create an entity on a client & server using ent_create, and then send messages to that client specifically from the server; Without the message going to all clients.

I believe SEND_STRING_TO(entpointer, stringtosend) should do the trick, but I just can't seem to get entpointer correct.

Any help, even examples of code would be really helpful. TIA

note: Running A6 Pro.
Posted By: SchokoKeks

Re: Server > Unique Client - [Help] - 08/18/08 21:15

here is the code I used. note that I'm not using an array, as there are 4 players max. and I'm not actually using send_xx_to, all clients get the same data in my system. too complicated otherwise..

Code:

define plid, skill1;

// on client:

	local_pl = ent_create ("dummy.mdl", vector (0,0,-5000), plent_act);
	sleep (2); // sleep time can be shorter, but in my game updates are only send every 2 seconds.
	while (local_pl.plid == 0) {wait (1);}
	local_faction = local_pl.plid;

[...]

// on server
function plent_event()
{
	if (EVENT_TYPE == EVENT_DISCONNECT)
	{
		ent_remove (me);
	}
}

function plent_act()
{
	my.enable_disconnect = 1;
	my.event = plent_event;

	if (pl1 == null) {my.plid = 1; pl1 = me; goto plent_slotsdone;}
	if (pl2 == null) {my.plid = 2; pl2 = me; goto plent_slotsdone;}
	if (pl3 == null) {my.plid = 3; pl3 = me; goto plent_slotsdone;}
	if (pl4 == null) {my.plid = 4; pl4 = me; goto plent_slotsdone;}
	diag ("\n all slots full?!");

	plent_slotsdone:

	sleep (2);
	send_skill (my.plid, null);
}



Posted By: indiGLOW

Re: Server > Unique Client - [Help] - 08/18/08 21:28

Thanks for the incredibly fast response smile

I am still not clear how you identify ClientA over ClientB.

when the client runs an ent_create(etc, etc, etc); how do I establish pointers on both the server and all clients?

I presume pl1, pl2 etc, are entity* definitions. How do you ensure that the pointers are correct for server and clients?

Thanks for the help, it's much appreciated. If it helps I can post my code?
Posted By: MrGuest

Re: Server > Unique Client - [Help] - 08/19/08 02:16

the only way i managed to achieve this was by sending a string to all clients and then from that string working out if it was intended for them and responding as needed else just ignoring it

there're new commands added in A7 (no use to you i know) but i think that they highlight some of the required events and commands in a6 don't exist
send_string (STRING*)
send_string_to (ENTITY*, STRING*)
send_string_id (var client_id, STRING*)

hope this helps somewhat...
Posted By: EpsiloN

Re: Server > Unique Client - [Help] - 08/19/08 03:41

Assign ID to all clients on server...
Example : number_of_cl += 1; my.id = number_of_cl
Use str_ functions and execute to assign a pointer with that ID to that entity and wait 1 second. Send the ID.
Client side , start a function that loops endlessly. In this function , go thru the list of entities , and if the current entity ID pointer is assigned , do nothing. Otherwise , assign it to that entity , again with str_ functions and execute.

If you dont understand it smile read it again...
Posted By: fastlane69

Re: Server > Unique Client - [Help] - 08/19/08 07:35

Quote:

I am still not clear how you identify ClientA over ClientB.


Epsilon gave a great answer! I would add that A7 has a client_id that may accomplish the same thing. cool
Posted By: indiGLOW

Re: Server > Unique Client - [Help] - 08/19/08 18:14

Thanks Epsolon, this may well make a great deal more sense, and allow me to get closer. The honest truth is a feel that I have created pointers as you describe, the trick is how I should reference them from the server to SEND_STRING_TO.

I've noticed several functions including things such as:

SEND_SKILL(EntityPointer.Skillx, "String to send"); where .Skillx is maybe a handle pointer to the entity?

Where as my use:
SEND_STRING_TO(EntityPointer, "String to send");

Doesn't seem to work. Now either my 'EntityPointer' is incorrect, or indeed my use of the function is incorrect. I've used ent_next to search through all entities, ensuring that a client entity with some unique identifier, such as ._client flag and playerID == n, but when I send string to this ent, I get nothing on the client.

IS it a case that I use SEND_STRING("String to Send") where "String to Send" includes text references that the Client then sorts through to see if the message was intended for it? i.e on recieving string from server, check if the message was for me? Compare my ID to the reference in the string?

I will refine my test code and post here, maybe you will be able to help me get my thick head around it. This should not be this hard smile

Thanks for the assistance both, your patience is exemplary grin

@MrGuest: Yes it always seems the function you need is better delivered in the next version smile There's always a next version...
Posted By: EpsiloN

Re: Server > Unique Client - [Help] - 08/20/08 03:57

fastlane69 , thats from my attempt at MMO wink

I think , for sending strings , you need to actualy put a string pointer there...I mean , player_name_str for example...to be predefined in your script. Otherwise the client wont know in wich string to save that text :P
Btw , I used and needed IDs only for the updating. When a client receives an array with updates , it updates the entity with the ID stored in the first variable...
Another 'ent type' skill identifies players and dummy entities or other objects...Thats how I know wich one is a player.
Posted By: fastlane69

Re: Server > Unique Client - [Help] - 08/20/08 16:37

Quote:
fastlane69 , thats from my attempt at MMO


Dude, I do the exact same thing in my MMO since it pre-dates client_ID. cool
Posted By: indiGLOW

Re: Server > Unique Client - [Help] - 08/20/08 19:04

Ok so I am still not getting this...so


1.Server starts up (all is calm)
2.Client Joins Server (Server Event! new Client)
3.Server sends everyone available player ID number
4.Client without ID assigns this as its identification number

some time later...

5.Server wants to send message to the client who got the ID
6.Server checks all entities until entity with correct ID is selected
7.Server sends message to that entity
8.Client that created the entity, gets a message???

I'm trying to understand the 'hand-shake' that goes on in order for the server to identify this client.

I will ensure my code follows this process (unless corrected) and see what happens. I'm still expecting the SEND_STRING_TO to not work. I hope I am wrong smile
Posted By: EpsiloN

Re: Server > Unique Client - [Help] - 08/20/08 20:27

The server sets client id in the player function that was given on the client when he ent_created the entity on the server... smile
After the server sets this client id , he sends it to all clients just before he sets my.nosend on.
Later , you go thru the list of clients , check if this ID is the same as the current entity on the list...If it is , send_var_to smile I never used send string instructions btw :P

What I didnt mention was , on the client , when a client receives a var , event_var is activated in the client event function (or was it another event name? I forgot already laugh )
If event var has been received , and the updating arrays first var is empty , calls a function that manages the updating array and distributes it to the entitys skills. After that it sets the updating array to 0. This will enshure , that , if you send another var , the updating vars Client ID is 0 , so , no updating will occur.

You've got it right , I just wanned to explain it better to avoid confusion smile
fastlane , I tought you used a plugin :P ?
Posted By: indiGLOW

Re: Server > Unique Client - [Help] - 08/20/08 21:32

Ok so during the server join event, I find an available player slot and broadcast a message to every client.

The string has a command code, and clients without an assigned ID get this number and assign it their client entity they created on the server.

the server should then be able to scan through all entities until it finds one with a matching ID and then send a message to that client through this entity.

Here's the final snippet, maybe there is something wrong here?

Code:
				// Find new Client entity 
				you = ent_next(null);
				while(you!=null){
					if(you._client)&&(you.player == tempID){me=you;}
					you = ent_next(you);	
				}
				SEND_STRING_TO(me, "Registered");


Currently the string "Registered" does not show up on the client. Any pointers?

Also I have noticed that some of my broadcast strings are not showing up complete on the clients. I send "Registered" but the clients display "Reg" any suggestions?

Thanks guys
Posted By: MrGuest

Re: Server > Unique Client - [Help] - 08/20/08 23:58

i'm reading this thinking that the ways i did it in A6 was really cr&p, now it seems everyone does it this way...

what i did was to create a login screen, then the client would click login after inputing his name and password and session_connect... this then sent a message to the server including the player_name (clients username), and password and then checked with the details the server held,

if all was ok at this point, the server would send back a message to all clients, but specifying it was for this certain client, so all other clients would ignore it... the recipient would update it's player_name with this requested username and giving it a unique ID,

any forthcoming messages would then reference this player_name so there is no chance of duplicaiton of username, and all updates would be done like this... unfortunately using this method all clients have to receive the string to realise if it's intended for them or not, and then act accordingly

this did have it's advantages however... if i was sending a string to a guild_name everyone in that guild would receive the string and act accordingly, and similarly to a team, raid or a private message. as long as i put enough information in that string for the client to determine what to do with it

hopefully this isn't the way everyone is thinking of doing things, but atm the way i'm reading it, it seems to be the only possible answer... smirk
Posted By: EpsiloN

Re: Server > Unique Client - [Help] - 08/21/08 03:42

When an event join is trigerred , you still dont have an entity for that client...maby thats the problem smile
You should set that ID number in the player function , so that you know for shure it is attached to a skill of your player entity.

As for the strings , you need a pointer , I think.
Code:
str_cpy(send_str,"Registered");
send_string_to(me,send_str);

Posted By: indiGLOW

Re: Server > Unique Client - [Help] - 08/22/08 20:19

I was pretty sure the server would not have a pointer assigned to the new client during the join event. I think this is exactly why the SEND_STRING_TO required an entity created by the client.

I also believe my script allows the client to join, get assigned a unique ID, create an entity on the server and set it's skill to the ID given out by the server.

I think there is a possibility I am going wrong here; maybe my entity skills are out of synch because I am getting the server to search for this new client during the join event itself? regardless of sleep(2)?

I have created a 2 second delay during the join_event, to allow the client to get the ID, spawn the entity and assign the skill. After the 2 seconds the server searches for an entity matching the ID and then sends a string to it directly.

Could it be the client created entity is not updated it's skill on the server?

I will look into this over the weekend. It would be fantastic if someone could give me a code snippet that demonstrates this. I keep thinking its the SEND_STRING_TO function itself, or maybe my A6.6 pro is acting up

As for the string issue, I have checked my code and I am passing the string through a function with a (_string) handler, and while I did have a few direct "" strings, it seems to be missing characters for all ways of sending.

I am going to have a crack at your example code.
Posted By: indiGLOW

Re: Server > Unique Client - [Help] - 08/26/08 21:16

Time for an update: Let me first tell you / show you where I am at:



In the above image you can see I have managed to get a client/host running, (larger image right)and 2 seperate clients (2 smaller images left), with each client and the server creating their own unique eyeball.

Each eyeball is following the server or clients own dev-cam, so gives a realtime representation of where they are in the world, and where they are looking.

All this is pretty cool. I've even got it running over the internet and performance is good.

However. It's all achieved on a wing and a prayer.

  • When clients disconnect the server has no clue who it was and so the clients entity stays resident.
  • when running over internet, server crashes when more than 1 client joins
  • I am still getting my head around where and when these functions are running
  • loads of un-needed stuff is being sent all the time
  • I am still not convinced I am getting unique pointers to clients, or am able to send exclusive strings


The quest into MP continues. - I've already been dealt a bombshell about encryption and A6, so I had to find something positive smile

Any help on the above listed items is welcome - TIA
Posted By: EpsiloN

Re: Server > Unique Client - [Help] - 08/27/08 03:42

Theres an event for disconnection , I'm not shure it was event_disconnect exactly smile look the manual. With the event , you dont need to know wich client disconnected.
About the other problems , I'd suggest you start again. I've written my MMO scripts over 15 times smile and the last one looks clean and works good and I know how to make it again in less than a day...
Posted By: indiGLOW

Re: Server > Unique Client - [Help] - 08/27/08 16:22

I have no doubt I will write this over and over and over again. Then when I think it's right, i'll write it again smile

Thanks Epsilon smile
Posted By: fastlane69

Re: Server > Unique Client - [Help] - 08/27/08 16:31

Quote:
fastlane , I tought you used a plugin :P ?


Nope. The only plugins we use are 1) a MySql plugin and 2) a number converter so we can store Vars accurate to .001 into MySql.

Out client update routine is much like you described. We assign each client a unique id from a master table and we transmit that ID to all clients. Then, whenever a message is sent (by string), this unique ID helps to identify which client the message is for. We use this technique to help us only move the clients we want... so that if Clients b-d are moving close to Client A but not close to Clients e-z, then we send a string with the instructions and unique id's for clients a-d and thus only people near you move.

No plugin needed for this, though a horrible pain to design and test to work.... which is why this is still tops on my list of "things the engine should do" since our system is nothing more than a bunch of lookup tables that we constantly have to reference. frown
Posted By: fastlane69

Re: Server > Unique Client - [Help] - 08/27/08 16:41

Quote:
However. It's all achieved on a wing and a prayer.

* When clients disconnect the server has no clue who it was and so the clients entity stays resident.


When you event_disconnect is called, before you run ent_remove, reference the skill upon which you have the client_ID and then use that to remove all client_ID's from everywhere.

Quote:

* when running over internet, server crashes when more than 1 client joins


That is not normal. Your login routine is not stable yet. You are likely over-righting on the wrong array or net index when coming in causing the server to crash. You should be able to debug this with proficient use of the Diag() command and acklog_sv.txt file.

Quote:

* I am still getting my head around where and when these functions are running


That's a good thing to get your head around, especially with MMOG. I recommend (if you haven't already) you look into UML diagramming and start diagramming your code. Trust me, it will seem like a waste of time at first, but in time, as the code grows and dependencies develop, it will be an invaluable tool in putting it all together.

Quote:

* loads of un-needed stuff is being sent all the time


Again, with UML you can map out your network traffic. Make sure you are using the Dplay_ function to set your server and client clocks. As well, pay attention to the nosends (I like to do nosend_all myself). Finally, get a Packet Sniffer to read through the packets you are sending. This will help identify what is being put on the net and this will help you find where it's coming from.

Quote:

* I am still not convinced I am getting unique pointers to clients, or am able to send exclusive strings


Let's not use the word "pointer" here shall we since it already has meaning in the engine. Instead, stick to "unique ID". wink

I'm surprised you are unable to send exclusive strings. This is something that A6 and A7 can do quite effortless. However, combining a unique client ID with sending strings can be confusing. In our case, we have a lookup table that converts our unique IDs into GS Handles. This way, whenever it comes time to put something on the network, we take the lookup the handle for a unique ID, use handle_to_pointer to get the pointer, and then use the pointer to send on. Convoluted but aside from the extra conversion step, quite easy.
Posted By: indiGLOW

Re: Server > Unique Client - [Help] - 08/28/08 12:37

I think one of the biggest problems is that I am now retro-fitting MP to my program, although I have replaced all template code and everything is written to be very modular.

Still that said, its difficult to get everything setup right.

Your reply is very useful, I appreciate the time you invested into this post. Thanks fastlane.

The comment you make about the term 'pointer' is very important, and I think this is mostly where I am falling down. Simply I am not sure what the SEND_*_TO function is expecting. I have taken a look at the latest AUM workshop, which has helped.

Still I have managed to get 'locally' several clients to connect, and for the server to update the positions of individual entities based on the local camera position from each client.

The server is able to seperate each client, based on the ID variable being passed from the server to the client, the wing and a prayer element comes here I think.

I am not getting a true handshake between client and server, and instead I am relying on operations taking a maximum of 2 seconds to complete, and then pushing ahead, presuming the information has been exchanged correctly.

So locally, with faster response times, this is maybe not an issue, however over the net 2 seconds might just not be enough time. More's the point, this is really bad code and both server and client should wait for each other until the exchange is complete, or indeed failed.

This is something I really need to re-write immediatly.

Your bang on about diagramming the code, laying out the exchange process is something I intend to invest considerable time in. This is something we are very thorough on at work and often the engineers are in meeting rooms re-drawing these connection diagrams.

Still, with my entire toolset to migrate to a client/server environment, my first step was simply to establish connection and simple avatar. This will allow the team to continue working with the tool and indeed share/discuss their work in a live environment.

With this in place I will then need to rip this baby apart and build her back up again smile Not the first or last time I will need to do this! lol - ripping out all the templates was fun smile

It sounds like you have already tackled many of the tough challenges ahead, for example, we will def want to include mySQL, we already have our servers in place and have committed to this route. (TBH Much based on your own posts about this over the past few years, as well as common trends and most importantly, accessibility.)

It's a great relief to know that someone has already walked this path and barring, d_play issues ;), I believe that we can achieve our ultimate goal.

Thanks for all your help and support fastlane.


Posted By: EpsiloN

Re: Server > Unique Client - [Help] - 08/28/08 20:19

You should know , if you're using A6 theres only one plugin for MySQL. And it is for MySQL 4 I think smile
It took me a week to figure out why it wasnt working with MySQL 5 :P
Posted By: indiGLOW

Re: Server > Unique Client - [Help] - 08/29/08 13:45

I believe we will have to bite the bullet and upgrade. However there is a load of work to do before thats needed, it's just means mySQL is another thing we're going to have to push back until A7.

It is a little anoying that I bought A6 Pro and have only really began using its functions in this last 18 months, and just as we're getting a clear road ahead we have to migrate to A7. What on earth did I do with all that time frown

Still I hope that when we do upgrade it will be to deliver the extra layer of polish, oh and of course mySQL.

Thanks for the info Epsilon, just another unwanted suprise...
© 2024 lite-C Forums