• Net messages behaving strangely
    18 replies, posted
I've been using quite a bit of net messages to send information. Then as of recently a strange case popped up, I went to update one of my addons and during the testing I noticed none of the changes I made applied. So I figure I screwed something up, then I went to the debugging stage by printing variables to the console. Still, nothing. So then I went as far as to remove the net message entirely. I tested it, and it still functioned as if nothing was changed. However, if I remove the addon, it will cease function entirely. But whenever it exists in the addons folder, it doesn't change. I figure gmod was storing this information somewhere and considered factory reset. That didn't work so I reinstalled gmod entirely. Didn't work either, I'm pretty confused here. I figured maybe it was an issue with addons, so I got rid of everything figuring something might've been overflowing and causing strange behavior, but that didn't do much. I'm just shooting in the dark at this point, even after deleting gmod entirely and reinstalling it, it didn't change anything. My only guess is gmod is storing this information externally, but I don't think so, even then, where would it be?
Im pretty sure you were either modified the wrong code or that the net messages were duped, because garrysmod doesnt store net messages, nor its callback. [editline]26th January 2017[/editline] Like, it just stores them on startup on tables, but it doesnt save them over files nor they are permanent
[QUOTE=Rocket;51728854]Could you post the net message code?[/QUOTE] Oh sure, why not? [CODE]net.Receive("clientsounds_client_s2c",function(len,ply) if cs_spawned == nil then return end local cs_player = net.ReadEntity() local cs_sound = net.ReadString() print("Local Player: " .. LocalPlayer() .. "\nCaller: " .. cs_player) if cs_player != LocalPlayer() then cs_player:EmitSound(cs_sound,90,100,1,CHAN_VOICE2) end cs_player:EmitSound(cs_sound,90,100,1,CHAN_VOICE) end)[/CODE] I wasn't sure how to paste this, since I don't do forums often.. but anyway, here's my shoddy-beginnerish code. This is for an addon I made specifically for my friends to play funny sounds from their player. Basically it's handled entirely server-client, no shared or in-between except to make sure the client downloads the client scripts. So it starts as a client-sided console command with a single parameter occupied by a string. So that string gets sent to the server, then the server broadcasts it to all clients as that net message (just being the one for the basic sound command). So what you see in that message, is sort of hacky, but it plays the sound once on the client, and twice for everyone who isn't the caller. Sort of a makeshift volume hack to make the sound play louder on other clients (otherwise it would be near inaudible). The thing is, the code works, it always worked. But nothing in the addon can be changed, since it seems to be reading somewhere else, and the initial changes I am making don't affect it.
Maybe that net receive function is not only there, but in another file which is overriding your changes, try looking around see if you can find it duped anywhere OR try searching for the net message name with something as N++. Also to paste code like that you should try putting it between [CODE] tags like so: [CODE] -- Hello my friend print("Hello world") [/CODE]
[QUOTE=geferon;51729011]Maybe that net receive function is not only there, but in another file which is overriding your changes, try looking around see if you can find it duped anywhere OR try searching for the net message name with something as N++. Also to paste code like that you should try putting it between [CODE] tags like so: [CODE] -- Hello my friend print("Hello world") [/CODE][/QUOTE] I used Search Everything and Windows Grep and scanned my entire HD. There is no duplications, could it possibly be something else?
[QUOTE=StellarLights;51729035]I used Search Everything and Windows Grep and scanned my entire HD. There is no duplications, could it possibly be something else?[/QUOTE] No that i can think of. It was just an addon right? We could take a look to its code and see if we find whats wrong. maybe you're using another netmessage. Just, look around for all net.receive functions inside of that addon, or umsg messages maybe
Could you post the code where you send the net message?
[QUOTE=MPan1;51729144]Could you post the code where you send the net message?[/QUOTE] Hey, why not? [CODE]net.Receive("clientsounds_client_c2s",function(len,ply) local cs_sound = net.ReadString() local cs_extension = string.GetExtensionFromFilename("garrysmod/sound/" .. cs_sound) if cs_extension == nil then cs_extension = ".ogg" else cs_sound = string.sub(cs_sound,1,string.len(cs_sound) - string.len(cs_extension)) end if cs_timescaling != 1 then net.Start("clientsounds_client_s2c") net.WriteEntity(ply) net.WriteString(cs_sound .. cs_extension) net.Broadcast() else if cs_time != 1.0 then net.Start("clientsounds_scaled_s2c") net.WriteEntity(ply) net.WriteString(cs_sound .. cs_extension) net.WriteFloat(game.GetTimeScale()) net.Broadcast() else net.Start("clientsounds_client_s2c") net.WriteEntity(ply) net.WriteString(cs_sound .. cs_extension) net.Broadcast() end end end)[/CODE] It's sloppy, but this is the net message received by the server, from the client. It is sent through a console command with a single parameter representing the string.
please put it inside [CODE] tags like so: [ CODE] YOUR CODE GOES HERE [ /CODE] but without spaces in between the [] things Also is it giving any errors? because youre changing the order of the elements you're writing
[QUOTE=geferon;51729209]please put it inside [CODE] tags like so: [ CODE] YOUR CODE GOES HERE [ /CODE] but without spaces in between the [] things Also is it giving any errors? because youre changing the order of the elements you're writing[/QUOTE] Thank you! And I don't think so? The only time I change the order is when the timescale is altered, then it has a unique net message for handling that to avoid unnecessary logic inside of the regular one.
Are you sure? Because on the original code of the clientside part of the message im not seeing anything at all that handles the float which you've sent him
[QUOTE=geferon;51729286]Are you sure? Because on the original code of the clientside part of the message im not seeing anything at all that handles the float which you've sent him[/QUOTE] Yeah, the only float is the timescale, which I haven't been messing with during the testing since I want to get the normal one working again. But it's strange, it didn't start acting up until I reorganized everything, and all I did was move all the code into unique files, I didn't change directories or order of definition, and everything has a unique name. Oh, one more thing; the code is practically unchanged, the only thing I added was the print line so I would know when it started working again. So the only change I made before it stopped making any changes was the organization. I forgot to mention, I reverted to a working backup, and stuck a print message in after it read the variables, and it still didn't change anything. I'm pretty sure it isn't the addon since this version worked all the time, and I debug with print pretty often.
[code] if cs_spawned == nil then return end [/code] ^ This is a bad idea. The net library has data waiting for you and you're not reading it if cs_spawned is nil. Make sure you read the data before you decide whether or not to return from the handler. If you don't, then who knows what could be waiting in the buffer the next time you receive a net message. All we know is, you have to read the data elements that you're being sent during a receive when you get a net message arrive. I would imagine that anything else is undefined behaviour.
[QUOTE=ph:lxyz;51730583][code] if cs_spawned == nil then return end [/code] ^ This is a bad idea. The net library has data waiting for you and you're not reading it if cs_spawned is nil. Make sure you read the data before you decide whether or not to return from the handler. If you don't, then who knows what could be waiting in the buffer the next time you receive a net message. All we know is, you have to read the data elements that you're being sent during a receive when you get a net message arrive. I would imagine that anything else is undefined behaviour.[/QUOTE] AFAIK you don't have to read all data, if a new message arrives the current buffer will simply be discarded and you won't read any unexpected crap.
[QUOTE=mijyuoon;51730773]AFAIK you don't have to read all data, if a new message arrives the current buffer will simply be discarded and you won't read any unexpected crap.[/QUOTE] While that is absolutely correct, I’d like to think of it as clean code, because that gets me into the correct mindset for future use in languages that does [b]not[/b] discard the buffer.
[QUOTE=Metamist;51731364]While that is absolutely correct, I’d like to think of it as clean code, because that gets me into the correct mindset for future use in languages that does [b]not[/b] discard the buffer.[/QUOTE] That was my line of thinking. I don't see why it would not discard it - but seeing as it's not otherwise documented as to what happens, we can't assume that it's safe to not read them.
[QUOTE=ph:lxyz;51730583][code] if cs_spawned == nil then return end [/code] ^ This is a bad idea. The net library has data waiting for you and you're not reading it if cs_spawned is nil. Make sure you read the data before you decide whether or not to return from the handler. If you don't, then who knows what could be waiting in the buffer the next time you receive a net message. All we know is, you have to read the data elements that you're being sent during a receive when you get a net message arrive. I would imagine that anything else is undefined behaviour.[/QUOTE] Yeah, that was intended. I noticed the net messages were crashing anyone who was connecting while it was being broadcast. I didn't know if there were any existing ways to check if someone is fully connected, so I just made a hook to declare that variable when the player initially spawned. Also, while I do appreciate the suggestions; the code I have written now is functional. I do want to optimize it, but I'm not focused on that because it's not reading anything I write. I've gone as far as deleting the entire net message and it still functions as if nothing was changed. Even if I wanted to optimize this code, I couldn't because it doesn't read any changes I make. I'm almost certain this information is being stored somewhere, otherwise the net message would spout out an error (being non-existent in the current file I'm working on). Would there be any guess to where that place might be?
[QUOTE=StellarLights;51733338]Yeah, that was intended. I noticed the net messages were crashing anyone who was connecting while it was being broadcast. I didn't know if there were any existing ways to check if someone is fully connected, so I just made a hook to declare that variable when the player initially spawned. Also, while I do appreciate the suggestions; the code I have written now is functional. I do want to optimize it, but I'm not focused on that because it's not reading anything I write. I've gone as far as deleting the entire net message and it still functions as if nothing was changed. Even if I wanted to optimize this code, I couldn't because it doesn't read any changes I make. I'm almost certain this information is being stored somewhere, otherwise the net message would spout out an error (being non-existent in the current file I'm working on). Would there be any guess to where that place might be?[/QUOTE] No, but the easiest solution to this kind of problems is changing the net message name by something else, and "unique", because maybe another addon is using it. If its still the same as now, then something is wrong with your code which i cant see.
Sorry, you need to Log In to post a reply to this thread.