usermessage?

I’m trying to make a simple adminmod. To communicate between client and server, i’m using usermessages.
(edit: no, i’m using “streamtoserver”)
But I don’t think the client succeed to send the ‘message’ with my code.

This is how I send it from client:



function ShowAdmin_sMenu()
	--stuff that shows the adminmenu and call the function Admin_ssend_request with required parameters
end
function Admin_sdone()
	Msg("The message has been send,")
end
function Admin_sdone(acc)
	if acc then
		Msg("and recived.
")
	else
		Msg("and not recived.
")
	end
end
function Admin_ssend_request(kind,req, par)		//Kind is wich type of command we use, only valid is "cons". req is the required command and par is the parameters
	Msg("Sending "..kind..", "..req..", "..par.."...
")
	datastream.StreamToServer( "Admin_s", { kind,req,par }, Admin_sdone, a_accepts );
end
 usermessage.Hook( "call_admin_s", ShowAdmin_sMenu )


And here is server:



Msg("1-...-")
require("datastream")	// ?
function GM:AcceptStream ( pl, handler, id ) // this is default. You only need to put this in if you need to reject it.
  return true
end

Msg("2-...-")

function Admin_s_recive( pl, handler, id, encoded, decoded )
 

  Msg ("Sender = " .. Pl:nick() .. "
") //Pl is the player that sent the data
  Msg ("handler = " .. handler .. "
") //handler is the name of the stream E.G. "Name_of_stream"
  for k,v in pairs(decoded) do
    Msg("received: "..k.."(v is "..v..")
")
  end

  
	if pl:IsAdmin() or pl:IsSuperAdmin() or pl:IsUserGroup("owner") or pl:IsUserGroup("Owner") then	//This is restricted area, if you are'nt a admin, turn around now!
		if decoded[1]=="cons" then //Consolle
			//Anything below will check the required command (if it is a command we want admins to be able to use)
			if decoded[2]=="kick" then
				game.ConsoleCommand("kick "..decoded[3].."
")
			end
		end
	else 
		Msg("DENIED!")
	end
  
end
datastream.Hook( "Admin_s", Admin_s_recive )
Msg("3-...--")


I used this wikisite and this tutorial to learn the stuff, but in the console I see the message from the function “Admin_ssend_request”, but I don’t get any of the done messages or anything from the server.
I can figure out what’s wrong, I both tested it singleplayer, lan server and on another server.

usermessage.Hook( “call_admin_s”, ShowAdmin_sMenu )

What is that for? Is ShowAdmin_sMenu declared somewhere else?

Also, how are you calling Admin_ssend_request?

Woops, forgot that one. I removed the gui-stuff from this code to make it look more simple.
should look better now, but how should do you know what’s wrong?

Through a function hooked to the chat. (and a console command to make it easier).
And a little mismatch: I dont use usermessages but I stream to the server…
But I got no problems getting my menus. Anyway, heres how i’m listing my “kick” buttons.



function Admin_sKick()
	//Get all players and their names
	local players_s={}
	players_s["n"]={}	//Name/Nick
	players_s["i"]={}	//ID/UniqueID
	
	local i=1
	for k,v in pairs(player.GetAll()) do	//All players
		players_s["n"]*=v:Nick()		//gets their name
		players_s["i"]*=v:UniqueID()	//and ID logged.
		i=i+1							//And i got another one ;)
	end
	
	/*---------------------------------------------------------------------------------------------------------
	Show the collected names in buttons that send the ban request and their UniqueID
	---------------------------------------------------------------------------------------------------------*/
	  local DermaPanel = vgui.Create( "DFrame" )
	DermaPanel:SetPos( 0,0 )
	DermaPanel:SetSize( 120, 20+i*40 )
	DermaPanel:SetTitle( "Choose a player (KICK)" ) // Name of Fram
	DermaPanel:SetVisible( true )
	DermaPanel:SetDraggable( true ) //Can the player drag the frame /True/False
	DermaPanel:ShowCloseButton( true ) //Show the X (Close button) /True/False
	DermaPanel:MakePopup()
 for ii=1,i do
	local DermaButton = vgui.Create( "DButton" )
	DermaButton:SetParent( DermaPanel ) // Set parent to our "DermaPanel"
	DermaButton:SetText( tostring(players_s["n"][ii]) )
	DermaButton:SetPos( 10, 10+ii*40 )
	DermaButton:SetSize( 100, 30 )
	DermaButton.DoClick = function ()
		Admin_ssend_request("cons","kick",players_s["i"][ii])// What happens when you press the button
	end 
 end
end


It’s before the functions to stream to server and after the main menu, but I don’t think there’s anything wrong with it…

[editline][/editline]why are you answering in a blue box?

Because he already asked that question and you didn’t answer.

:slight_smile:

Derp.

[lua]Msg ("Sender = " … Pl:nick() … "
") //Pl is the player that sent the data[/lua]

On the server should be

[lua]Msg ("Sender = " … pl:nick() … "
") //Pl is the player that sent the data[/lua]

You used Pl instead of pl. Breaks the whole thing.

Arh, thank you for helping!!!

Nobody understands the case sensativity of lua anymore?

There is no “nick” value in the player metatable, there is “Nick”.

Ah yes that too.

Hmm, tagged out the whole “Msg” part, and replaced it with a single msg that should tell me that there was a stream, but it don’t occur in the console. But I got the other Msg (1, 2 and 3) that tells me that all is alright. (after I removed the GM:AcceptStream function).
Now theres no errors from that file in the console but I still don’t get any response from the server…

Post new code.

Full code:
cl_admin_s.lua
[lua]
include( ‘shared.lua’ )
//Another GREAT thanks for the wikia pages!
function ShowAdmin_sMenu() //Makes players able to change their team through gui: http://wiki.garrysmod.com/?title=Derma_Tutorial2
local DermaPanel = vgui.Create( “DFrame” )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 450, 275 )
DermaPanel:SetTitle( “Choose Your Team” ) // Name of Fram
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true ) //Can the player drag the frame /True/False
DermaPanel:ShowCloseButton( true ) //Show the X (Close button) /True/False
DermaPanel:MakePopup()

//Text:
local DermaText = vgui.Create (“Label”)
DermaText:SetParent( DermaPanel )
DermaText:SetPos( 175, 50 )
DermaText:SetText("FSS Admin_s menu.
Everyone is able to
wach, but not use!
")
DermaText:SetSize( 200, 100 )

//Buttons ->
local DermaButton = vgui.Create( “DButton” )
DermaButton:SetParent( DermaPanel ) // Set parent to our “DermaPanel”
DermaButton:SetText( “Kick” )
DermaButton:SetPos( 25, 50 )
DermaButton:SetSize( 150, 50 )
DermaButton.DoClick = function ()
Admin_sKick()// What happens when you press the button
end

//<- Buttons

end
//More menus
function Admin_sKick()
//Get all players and their names
local players_s={}
players_s[“n”]={} //Name/Nick
players_s[“i”]={} //ID/UniqueID

local i=1
for k,v in pairs(player.GetAll()) do	//All players
	players_s["n"]*=v:Nick()		//gets their name
	players_s["i"]*=v:UniqueID()	//and ID logged.
	i=i+1							//And i got another one ;)
end

/*---------------------------------------------------------------------------------------------------------
Show the collected names in buttons that send the ban request and their UniqueID
---------------------------------------------------------------------------------------------------------*/
  local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 0,0 )
DermaPanel:SetSize( 120, 20+i*40 )
DermaPanel:SetTitle( "Choose a player (KICK)" ) // Name of Fram
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true ) //Can the player drag the frame /True/False
DermaPanel:ShowCloseButton( true ) //Show the X (Close button) /True/False
DermaPanel:MakePopup()

for ii=0,i do
local DermaButton = vgui.Create( “DButton” )
DermaButton:SetParent( DermaPanel ) // Set parent to our “DermaPanel”
DermaButton:SetText( tostring(players_s[“n”][ii]) )
DermaButton:SetPos( 10, 10+ii*40 )
DermaButton:SetSize( 100, 30 )
DermaButton.DoClick = function ()
Admin_ssend_request(“cons”,“kick”,players_s[“i”][ii])// What happens when you press the button
end
end
end

//Send information to the server
function Admin_sdone()
Msg(“The message has been send,”)
end
function Admin_sdone(acc)
if acc then
Msg("and recived.
")
else
Msg("and not recived.
")
end
end
function Admin_ssend_request(kind,req, par) //Kind is wich type of command we use, only valid is “cons”. req is the required command and par is the parameters
Msg("Sending “…kind…”, “…req…”, “…par…”…
")
datastream.StreamToServer( “Admin_s”, { kind,req,par }, Admin_sdone, a_accepts );
end
usermessage.Hook( “call_admin_s”, ShowAdmin_sMenu ) //Open menu and stuff like that
concommand.Add(“menu_s”, ShowAdmin_sMenu )

[/lua]

sv_admin_s.lua
[lua]
Msg(“1---------------------------------------------------------------------------------------------------------------------------------------------”)
require(“datastream”) // ?
/function GM:AcceptStream ( pl, handler, id ) // this is default. You only need to put this in if you need to reject it.
return true
end
/

Msg(“2---------------------------------------------------------------------------------------------------------------------------------------------”)

function Admin_s_recive( pl, handler, id, encoded, decoded )

/*
Msg ("Sender = " … pl:nick() … "
") //Pl is the player that sent the data
Msg ("handler = " … handler … "
") //handler is the name of the stream E.G. “Name_of_stream”
for k,v in pairs(decoded) do
Msg("received: “…k…”(v is “…v…”)
")
end
*/
Msg("SERVER: RECIVED DATASTREAM
")
if pl:IsAdmin() or pl:IsSuperAdmin() or pl:IsUserGroup(“owner”) or pl:IsUserGroup(“Owner”) then //This is restricted area, if you are’nt a admin, turn around now!
if decoded[1]==“cons” then //Consolle
//Anything below will check the required command (if it is a command we want admins to be able to use)
if decoded[2]==“kick” then
game.ConsoleCommand("kick “…decoded[3]…”
")
end
end
else
Msg(“DENIED!”)
end

end
datastream.Hook( “Admin_s”, Admin_s_recive )
Msg(“3---------------------------------------------------------------------------------------------------------------------------------------------”)
[/lua]

This is the code after edit…

edit: Actually, what I need is to know how to tell the server what the client want, and some parameters…