Advertisement
Guest User

Untitled

a guest
May 3rd, 2012
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.50 KB | None | 0 0
  1.  
  2. if SERVER then -- START OF SERVER
  3.  
  4. local DefaultMotdInfo = [[
  5. snip
  6. ]]
  7.  
  8. local DefaultMotw = "Testing new MOTD!"
  9. local DefaultAdmins = ""
  10.  
  11. function CheckForMOTD()
  12.     if !file.Exists( "motd/motw.txt" ) and !file.Exists( "motd/admins.txt" ) and !file.Exists( "motd/rules.txt" ) then
  13.         file.CreateDir( "motd/" )
  14.     end
  15.     if !file.Exists( "motd/motw.txt" ) then
  16.         file.Write( "motd/motw.txt", DefaultMotw )
  17.     end
  18.     if !file.Exists( "motd/admins.txt" ) then
  19.         file.Write( "motd/admins.txt", DefaultAdmins )
  20.     end
  21.     if !file.Exists( "motd/rules.txt" ) then
  22.         file.Write( "motd/rules.txt", DefaultMotdInfo )    
  23.     end
  24. end
  25. CheckForMOTD()
  26.  
  27. local bitsize = 32 -- I'm not sure exactly how much text can be sent alongside pointers so you can toy with this number
  28. local bits = {}
  29.  
  30. function GetMoTD()
  31.     local txt = file.Read("motd/rules.txt")
  32.     bits = {} -- Clears the table in case the function is ran again (loading a new motd)
  33.     while (string.len(txt) > bitsize) do
  34.         local bit = string.sub(txt, 1, bitsize)
  35.         table.insert(bits, bit)
  36.          
  37.         txt = string.sub(txt, bitsize + 1)
  38.     end
  39. end
  40.  
  41. function GetAdmins()
  42.     local txt = file.Read("motd/admins.txt")
  43.     bits = {} -- Clears the table in case the function is ran again (loading a new motd)
  44.     while (string.len(txt) > bitsize) do
  45.         local bit = string.sub(txt, 1, bitsize)
  46.         table.insert(bits, bit)
  47.          
  48.         txt = string.sub(txt, bitsize + 1)
  49.     end
  50. end
  51.  
  52. function GetMotw()
  53.     local txt = file.Read("motd/motw.txt")
  54.     bits = {} -- Clears the table in case the function is ran again (loading a new motd)
  55.     while (string.len(txt) > bitsize) do
  56.         local bit = string.sub(txt, 1, bitsize)
  57.         table.insert(bits, bit)
  58.          
  59.         txt = string.sub(txt, bitsize + 1)
  60.     end
  61. end
  62.  
  63. hook.Add( "PlayerInitialSpawn", "SendPlayerMOTD", function( ply )
  64.     print( ply:Nick() )
  65.     SendRules(ply)
  66. end )
  67.  
  68. function SendRules(pl)
  69.     GetMoTD()
  70.     for k, v in pairs(bits) do
  71.         umsg.Start("RecieveRules", pl)
  72.             umsg.Short(k) -- k ranges from 1 to #bits and is in order because of the while function. It can serve as the pointer
  73.             umsg.Short(#bits) -- Tells the client how many bits are in the entire MoTD so it knows when to stitch them
  74.             umsg.String(v)
  75.         umsg.End()
  76.     end
  77.     SendAdmins(pl)
  78. end
  79.  
  80. function SendAdmins(pl)
  81.     GetAdmins()
  82.     for k, v in pairs(bits) do
  83.         umsg.Start("RecieveAdmins", pl)
  84.             umsg.Short(k) -- k ranges from 1 to #bits and is in order because of the while function. It can serve as the pointer
  85.             umsg.Short(#bits) -- Tells the client how many bits are in the entire MoTD so it knows when to stitch them
  86.             umsg.String(v)
  87.         umsg.End()
  88.     end
  89.     SendMotw(pl)
  90. end
  91.  
  92. function SendMotw(pl)
  93.     GetMotw()
  94.     for k, v in pairs(bits) do
  95.         umsg.Start("RecieveMotw", pl)
  96.             umsg.Short(k) -- k ranges from 1 to #bits and is in order because of the while function. It can serve as the pointer
  97.             umsg.Short(#bits) -- Tells the client how many bits are in the entire MoTD so it knows when to stitch them
  98.             umsg.String(v)
  99.         umsg.End()
  100.     end
  101. end
  102.  
  103. end -- END OF SERVER
  104.  
  105. if CLIENT then
  106.  
  107. local RulesInfo = ""
  108. local AdminsInfo = ""
  109. local MotwInfo = ""
  110.  
  111. local Rulesbits = {}
  112. local Adminsbits = {}
  113. local Motwbits = {}
  114.  
  115. usermessage.Hook( "RecieveRules", function(u)
  116.     local bitnum = u:ReadShort()
  117.     local numbits = u:ReadShort()
  118.     local bit = u:ReadString()
  119.      
  120.     Rulesbits[bitnum] = bit
  121.      
  122.     if (#bits == numbits) then -- Stitch the MoTD
  123.         RulesInfo = table.concat(Rulesbits, "")
  124.     end
  125. end )
  126.  
  127. usermessage.Hook( "RecieveAdmins", function(u)
  128.     local bitnum = u:ReadShort()
  129.     local numbits = u:ReadShort()
  130.     local bit = u:ReadString()
  131.      
  132.     Adminsbits[bitnum] = bit
  133.      
  134.     if (#bits == numbits) then -- Stitch the MoTD
  135.         AdminsInfo = table.concat(Adminsbits, "")
  136.     end
  137. end )
  138.  
  139. usermessage.Hook( "RecieveMotw", function(u)
  140.     local bitnum = u:ReadShort()
  141.     local numbits = u:ReadShort()
  142.     local bit = u:ReadString()
  143.      
  144.     Motwbits[bitnum] = bit
  145.      
  146.     if (#bits == numbits) then -- Stitch the MoTD
  147.         MotwInfo = table.concat(Motwbits, "")
  148.         Welcome()
  149.     end
  150. end )
  151.  
  152. function Welcome()
  153.     MainMenu = vgui.Create( "DFrame" )
  154.         MainMenu:SetPos( 450, 190 )
  155.         MainMenu:SetSize( 360, 455 )
  156.         MainMenu:SetTitle( "MOTD" )
  157.         MainMenu:SetBackgroundBlur( true )
  158.         MainMenu:SetVisible( true )
  159.         MainMenu:SetDraggable( false )
  160.         MainMenu:ShowCloseButton( false )
  161.         MainMenu:MakePopup()
  162.  
  163.    
  164.     PropertySheet = vgui.Create( "DPropertySheet")
  165.         PropertySheet:SetParent( MainMenu )
  166.         PropertySheet:SetPos( 5, 30 )
  167.         PropertySheet:SetSize( 350, 340 )
  168.    
  169.     local DermaButton = vgui.Create( "DButton", DermaPanel )
  170.         DermaButton:SetText( "Agree" )
  171.         DermaButton:SetSize( 165, 75 )
  172.         DermaButton:SetPos( 7, 373 )
  173.         DermaButton:SetParent( MainMenu )
  174.         DermaButton.DoClick = function()
  175.             MainMenu:Close()
  176.             RunConsoleCommand( "say", "I have read and agree with the rules")
  177.         end
  178.    
  179.     local DermaButton = vgui.Create( "DButton", DermaPanel )
  180.         DermaButton:SetText( "Disagree" )
  181.         DermaButton:SetSize( 165, 75 )
  182.         DermaButton:SetPos( 190, 373 )
  183.         DermaButton:SetParent( MainMenu )
  184.         DermaButton.DoClick = function()
  185.             MainMenu:Close()
  186.             surface.PlaySound( "buttons/button8.wav" )
  187.             RunConsoleCommand( "say", "I disagree with the rules, I will now be disconnected.")
  188.             RunConsoleCommand( "disconnect" )
  189.         end
  190.  
  191.     local TabOne = vgui.Create( "DPanel" ) --Rules
  192.         TabOne:SetVisible( true )
  193.         local Info = vgui.Create("DLabel", TabOne)
  194.             Info:SetText(
  195.                         [[ Welcome to ]] .. GetHostName() .. [[!
  196.                        
  197.                        
  198.                         MOTW: ]] .. MotwInfo .. [[
  199.                        
  200.                        
  201.                         Rules: ]] .. RulesInfo .. [[
  202.                         ]]
  203.  
  204.                         )
  205.             Info:SetTextColor( Color( 0, 0, 0, 255 ) )
  206.             Info:SetPos( 5, 20 )
  207.             Info:SizeToContents( )
  208.  
  209.     local TabThree = vgui.Create( "DPanel" ) --Donate
  210.         TabThree:SetVisible( true )
  211.         local Info = vgui.Create("DLabel", TabThree)
  212.             Info:SetText( "" )
  213.             Info:SetTextColor( Color( 0, 0, 0, 255 ) )
  214.             Info:SetPos( 5, 20 )
  215.             Info:SizeToContents( )
  216.            
  217.     local TabTwo = vgui.Create( "DPanel" ) --Admins
  218.         TabTwo:SetVisible( true )
  219.         local Info = vgui.Create("DLabel", TabTwo)
  220.             Info:SetText( AdminsInfo )
  221.             Info:SetTextColor( Color( 0, 0, 0, 255 ) )
  222.             Info:SetPos( 5, 20 )
  223.             Info:SizeToContents( )
  224.  
  225.     local TabFour = vgui.Create( "DPanel" ) --Events
  226.         TabThree:SetVisible( true )
  227.         local Info = vgui.Create("DLabel", TabFour)
  228.             Info:SetText( [[
  229.                              snip
  230.                           ]]
  231.                         )
  232.             Info:SetTextColor( Color( 0, 0, 0, 255 ) )
  233.             Info:SetPos( 5, 20 )
  234.             Info:SizeToContents( )
  235.        
  236.     local TabFive = vgui.Create( "DPanel" ) --Servers
  237.         TabThree:SetVisible( true )
  238.         local Info = vgui.Create("DLabel", TabFive)
  239.             Info:SetText( [[
  240.                 Servers:
  241.                snip
  242.                           ]]
  243.                         )
  244.             Info:SetTextColor( Color( 0, 0, 0, 255 ) )
  245.             Info:SetPos( 5, 20 )
  246.             Info:SizeToContents( )
  247.  
  248.     PropertySheet:AddSheet( "Rules", TabOne, "gui/silkicons/exclamation", false, false, "Rules!" )
  249.     PropertySheet:AddSheet( "Admins", TabTwo, "gui/silkicons/shield", false, false, "Admins!" )
  250.     PropertySheet:AddSheet( "Donate", TabThree, "gui/silkicons/heart", false, false, "Donate!" )
  251.     --PropertySheet:AddSheet( "Events", TabFour, "gui/silkicons/group", false, false, "Events!" )
  252.     PropertySheet:AddSheet( "Servers", TabFive, "gui/silkicons/page_white_wrench", false, false, "Servers!" )
  253.  
  254. end
  255. concommand.Add("OpenMotd", Welcome )
  256.  
  257. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement