• OOSocks
    279 replies, posted
Close the socket on the shutdown hook. [editline]05:05PM[/editline] There is no such thing as the PreChangeLevel hook. [url]http://wiki.garrysmod.com/?title=Gamemode.ShutDown[/url] [lua] hook.Add("ShutDown", "SocketPreChangeLevel", SocketPreChangeLevel) [/lua]
PreChangeLevel is custom hook, called from gamemode right before mapchange.(sorry for answering instead kna, but he is away). Looks like closing socket before changelevel isn't helps anyway.
Im using socketing on my 3 dedis and i have no problem, even not while restarting my server.... are you sure you have last build?
I would rather rely on the ShutDown hook than something made in the gamemode.
Just finished my tests. Same thing happened even with shutdown hook. All 3 dedicated servers uses Windows Server 2003 x64 - maybe problem in that? Interesting fact - that crashes does not generate MDMPs - should they?
Running on windows server 2008 x64 here, maybe download the binary pack thingy.
[QUOTE=Hardy;23113348]Just finished my tests. Same thing happened even with shutdown hook. All 3 dedicated servers uses Windows Server 2003 x64 - maybe problem in that? Interesting fact - that crashes does not generate MDMPs - should they?[/QUOTE] Sure? Cause the new Gmod version dumps your mdmp's into the root of the drive etc "C:\dumps"
Does anyone have a working HTTP request function? the example one wont work and i cant get it to whatever i do
Can you show us?
Basicly the page source code ends up in the headrs when using your example, i have tried alot but nothing wants to work [editline]09:29AM[/editline] Some webpages dosent even have a content length [editline]10:08AM[/editline] Bah i got it
Trying to do a server query, but it wont respond [lua]require("oosocks") local connection = OOSock(IPPROTO_UDP); connection:SetCallback(function(socket, callType, callId, err, data, peer, peerPort) if(callType == SCKCALL_BIND && err == SCKERR_OK) then print("Bound."); connection:Send("\255\255\255\255TSource Engine Query\0", "91.192.210.199", 27015); connection:ReceiveDatagram(); end if(callType == SCKCALL_SEND && err == SCKERR_OK) then print("Sent."); end if(callType == SCKCALL_REC_DATAGRAM && err == SCKERR_OK) then print("Got '" .. data .. "' from " .. peer .. ":" .. tostring(peerPort)); socket:Close() end if(err != SCKERR_OK) then socket:Close() end end); connection:Bind("", 27015);[/lua] [editline]04:18PM[/editline] Can you please make it possible to send NULLs? shouldent be too hard as strings in lua isnt NULL terminated, and string.len("lol\0wut") returns 7
Gmod API doesn't support it. I will do something like {"String", 0, "Bob", 23} Which would equate to "String\0Bob\23"
Chrisaster tested, strings in lua isnt NULL terminated, so it should be simple
[url]http://www.facepunch.com/showpost.php?p=23378927&postcount=203[/url] If string.len works then you might even be able to use ILuaInterface::StringLength instead of manual specification.
string.len works just fine [editline]06:20PM[/editline] Read the help description thingy on StringLength, it says lua strings can have nulls [editline]06:23PM[/editline] [cpp]LUA_FUNCTION(ReadString) { gLua->CheckType(1, GLua::TYPE_STRING); const char *str = Lua()->GetString(1); unsigned int len = Lua()->StringLength(1); Msg("STR["); for (unsigned int i=0;i<len;i++) Msg("%c", str[i]); Msg("]\n"); return 0; } [/cpp] Crashed me, but its becuse of enginespew/something else is messing up i think [editline]06:29PM[/editline] StingLength cause a crash on any string
Anyone got a working server query (not masterserver) script? I'm not getting it :(
Source server queries must end with a NULL char if i recall correctly
[QUOTE=Tobba;23406188]Source server queries must end with a NULL char if i recall correctly[/QUOTE] Yes, because "Source Engine Query" is a NULL terminated string.
I've fixed the module so you can use strings with null characters. But, I cant release it until Garry adds a function to GMod to allow pushing sized strings. I cant do it(not easily) since lua_pushlstring is not included in lua_shared since its taken out at link time. And gmod lua uses non standard lua_State structure, so I can't compile my own in.
Updated with BinRead.
Have you added ReadString here too? :D
Could we have a TCP Server example? I can't seem to get mine to work. Oh and linux oosocks is outdated. It should now be _linux.dll Plus some of the engine files changed name.
Updated Linux. [editline]01:41PM[/editline] Example TCP server acceptor. Might not work, but thats the concept. [lua]require("OOSocks"); local clients = {}; local function ClientSockCallback(socket, callType, callId, err, data, peer, peerPort) if(err != SCKERR_OK) then Error(err); end if(callType == SCKCALL_REC_LINE) then print(data); if(data != "END") then socket:ReceiveLine(); -- If the client hasnt told us they are done, read annother line! end end end -- This is our listen socket. It will just accept every socket into clients. local ServerSock = OOSock(IPPROTO_TCP); ServerSock:SetCallback(function(socket, callType, callId, err, data, peer, peerPort) if(err != SCKERR_OK) then Error(err); end if(callType == SCKCALL_BIND) then socket:Listen(10); end if(callType == SCKCALL_LISTEN) then socket:Accept(); end if(callType == SCKCALL_ACCEPT) then print("Got client " .. peer .. "\n"); data:SetCallback(ClientSockCallback); data:ReceiveLine() -- Lets for some reason, read 1 line. table.insert(clients, data); -- I dunno, we might need em. -- Accept annother socket. socket:Accept(); end end) ServerSock:Bind("", 1000);[/lua]
We will we are able to send binary stuff?
You can send binary as a string. It supports \0
Updated fixing Accept socket bug.
For some reason even your example code results into [CODE]attempt to call a userdata value[/CODE] on console. No error lines or anything. Really confusing.
Yeah thats the fix. ;) update the .dll
Linux build too, please? ;) I haven't had luck compiling in linux yet.
Updated linux.
Sorry, you need to Log In to post a reply to this thread.