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:
[code]
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.\n")
else
Msg("and not recived.\n")
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.."...\n")
datastream.StreamToServer( "Admin_s", { kind,req,par }, Admin_sdone, a_accepts );
end
usermessage.Hook( "call_admin_s", ShowAdmin_sMenu )
[/code]
And here is server:
[code]
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() .. "\n") //Pl is the player that sent the data
Msg ("handler = " .. handler .. "\n") //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..")\n")
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].."\n")
end
end
else
Msg("DENIED!")
end
end
datastream.Hook( "Admin_s", Admin_s_recive )
Msg("3-...--")
[/code]
I used [url=http://wiki.garrysmod.com/?title=Datastream.StreamToServer]this[/url] wikisite and [url=http://wiki.garrysmod.com/?title=Client_to_Server]this[/url] 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?
[QUOTE=yakahughes;20013566]
Also, how are you calling Admin_ssend_request?[/QUOTE]
[QUOTE=yakahughes;20022800][/QUOTE]
Through a function hooked to the chat. (and a console command to make it easier).
And a little mismatch: I dont use [i]usermessages[/i] but I stream to the server...
But I got no problems getting my menus. Anyway, heres how i'm listing my "kick" buttons.
[code]
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"][i]=v:Nick() //gets their name
players_s["i"][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
[/code]
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?
[QUOTE=Herover;20024738]why are you answering in a blue box?[/QUOTE]
Because he already asked that question and you didn't answer.
:)
Derp.
[lua]Msg ("Sender = " .. Pl:nick() .. "\n") //Pl is the player that sent the data[/lua]
On the server should be
[lua]Msg ("Sender = " .. pl:nick() .. "\n") //Pl is the player that sent the data[/lua]
You used Pl instead of pl. Breaks the whole thing.
[QUOTE=yakahughes;20026276]
You used Pl instead of pl. Breaks the whole thing.[/QUOTE]
Arh, thank you for helping!!!
[QUOTE=iRzilla;20027528]Nobody understands the case sensativity of lua anymore?
There is no "nick" value in the player metatable, there is "Nick".[/QUOTE]
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...
[QUOTE=Herover;20040486]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...[/QUOTE]
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: [url]http://wiki.garrysmod.com/?title=Derma_Tutorial2[/url]
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. \n Everyone is able to \n wach, but not use! \n")
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"][i]=v:Nick() //gets their name
players_s["i"][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.\n")
else
Msg("and not recived.\n")
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.."...\n")
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() .. "\n") //Pl is the player that sent the data
Msg ("handler = " .. handler .. "\n") //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..")\n")
end
*/
Msg("SERVER: RECIVED DATASTREAM\n")
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].."\n")
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...
Sorry, you need to Log In to post a reply to this thread.