Net Receive problems

Hey

When i call a function inside of net receive in the server side file, and its a serverside function it equals nil. But if i run another function without going through net recieve it runs the server side functions fine



util.AddNetworkString("Rpname")
util.AddNetworkString("SetRpName")
util.AddNetworkString("SendUndo")

hook.Add("InitPostEntity", "removeRPSetMoney", function()
	DarkRP.removeChatCommand("rpname")
	DarkRP.removeChatCommand("nick")
	DarkRP.removeChatCommand("name")
	concommand.Remove("undo") 
end)

net.Receive("SetRpName", function()
	local ply = net.ReadEntity()
	local name = net.ReadString()
	
	SetTheName(ply, name)
end)

function SetTheName(ply, name)
       ply:setRPName(name, false)
end

hook.Add("PlayerSay", "Setthatvalue", function(ply, text, team)
	SetTheName(ply, text)
end)



I have no clue what your objective is here… But why are you saving the players ‘requested’ rpname into a table when you can just do ply:setRPName() in the net.Receive ?

I was trying to make a way to be able to do server side functions. If i put the functions in net receive it doenst work, and that is the problem.

Can you post your send function?




hook.Add( "PlayerFullyConnected", "PlayerFullyConnectedExample", function(ply)

	local ply = net.ReadEntity()
	local Frame = vgui.Create( "DFrame" )
	Frame:SetSize( 400, 400 )
	Frame:SetTitle( "" )
	Frame:SetVisible( true )
	Frame:SetDraggable( false )
	Frame:ShowCloseButton( true )
	Frame:MakePopup()
	Frame:Center()
	Frame.Paint = function()
		draw.RoundedBox( 0, 2, 2, Frame:GetWide()-4, Frame:GetTall()-4, Color( 28, 28, 28, 255 ) )
		draw.RoundedBox( 0, 8, 8, Frame:GetWide()-16, 50, Color( 255, 255, 255, 255 ) )
	end
	
	local Title = vgui.Create("DLabel", Frame)
	Title:SetPos(20,17) 
	Title:SetColor(Color(0, 0, 0, 255)) 
	Title:SetFont("TitleFont")
	Title:SetText("Rpname") 
	Title:SizeToContents() 
	
	local Button = vgui.Create( "DButton", Frame )
	Button:SetText( "Firstname:" )
	Button:SetTextColor( Color( 255, 255, 255 ) )
	Button:SetPos( 70, 100 )
	Button:SetSize( 70, 30 )
	Button.Paint = function( self, w, h )
		draw.RoundedBox( 0, 0, 0, w, h, Color( 41, 128, 185, 250 ) ) -- Draw a blue button
	end
	Button.DoClick = function()
		print( "I was clicked!" )
	end
	
	local firstname = vgui.Create("DTextEntry", Frame)
	firstname:SetText("")
	firstname:SetMultiline(false)
	firstname:SetSize(200,30) 
	firstname:SetPos(140, 100)
	
	local ButtonFirst = vgui.Create( "DButton", Frame )
	ButtonFirst:SetText( "Firstname:" )
	ButtonFirst:SetTextColor( Color( 255, 255, 255 ) )
	ButtonFirst:SetPos( 70, 200 )
	ButtonFirst:SetSize( 70, 30 )
	ButtonFirst.Paint = function( self, w, h )
		draw.RoundedBox( 0, 0, 0, w, h, Color( 41, 128, 185, 250 ) ) -- Draw a blue button
	end
	Button.DoClick = function()
		print( "I was clicked!" )
	end
	
	local lastname = vgui.Create("DTextEntry", Frame)
	lastname:SetText("")
	lastname:SetMultiline(false)
	lastname:SetSize(200,30) 
	lastname:SetPos(140, 200)
	
	local submit = vgui.Create( "DButton", Frame)
	submit:SetPos(70, 300)
	submit:SetText("")
	submit:SetSize( 272, 30 )
	submit.DoClick = function()
		if not firstname:GetValue() == nil and lastname:GetValue() == nil then
			print("Debug 1")
			net.Start("SetRpName")
				net.WriteEntity(ply)
				net.WriteString(firstToUpper(firstname:GetValue()).." "..firstToUpper(lastname:GetValue()))
			net.SendToServer()
			print("Debug 2")
			Frame:Close()
		end
	end
	submit.Paint = function(self, w, h)
		draw.RoundedBox( 0, 0, 0, w, h, Color( 41, 128, 185, 250 ) )
	end
	
	local Title = vgui.Create("DLabel", Frame)
	Title:SetPos(165,302) 
	Title:SetColor(Color(255, 255, 255, 255)) 
	Title:SetFont("SubmitFont")
	Title:SetText("Submit") 
	Title:SizeToContents() 
end );

PlayerFullyConnected isn’t a real hook, unless you added that yourself and are hook.Run-ing it in PlayerInitialSpawn (why you would I don’t know).

Anyways,



local ply = net.ReadEntity()


Are you running this inside of a net.Receive function? You can just do LocalPlayer() to get the player clientside.



net.Start("SetRpName")
    net.WriteEntity(ply)
    net.WriteString(firstToUpper(firstname:GetValue()).." "..firstToUpper(lastname:GetValue()))
net.SendToServer()


There should be no reason to EVER send the client in a Client->Server net message; it’s terribly insecure. Imagine what could happen if sv_allowcslua was set to 1. net.Receive on the serverside has an argument which gives you the player who sent the net message.

Here’s an example of how to do a name setting system. Don’t copy it word for word, it’s code from an old project I stopped working on over a year ago, but you get the jist.

Sending Client->Server sometimes is necessary and they shouldn’t be considered insecure. As long as you have sv_allowcslua set to 0 and log whoever sends them (By detouring net.receive on SV). Another thing that he did do is:


net.WriteEntity(ply)

You never need to send the LocalPly through a net message because net.receive gives you the players entity:


 net.Receive("SetRpName",function(ply) <--- PLY 

Thanks it works now