Skip to content

Commit

Permalink
Merge pull request #139 from mc-server/Motd
Browse files Browse the repository at this point in the history
You can now use @ properly in the motd
  • Loading branch information
bearbin committed May 19, 2015
2 parents 9e15b17 + 116184e commit 5171b43
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function KickPlayer( PlayerName, Reason )
end


function ReturnColorFromChar( Split, char )
function ReturnColorFromChar(char)

-- Check if the char represents a color. Else return nil.
if char == "0" then
Expand Down
34 changes: 15 additions & 19 deletions motd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,31 @@ end

function LoadMotd()

local File = io.open( "motd.txt", "r" )

-- Check if the file 'motd.txt' exists, else create it.
if not File then
if (not cFile:Exists("motd.txt")) then
CreateFile = io.open( "motd.txt", "w" )
CreateFile:write("@6Welcome to the MCServer test server!\n@6http://www.mc-server.org/\n@6Type /help for all commands")
CreateFile:close()
else
File:close()
end

for line in io.lines( "motd.txt" ) do
local TempMessage = line
-- Do a for loop that goes to each char in the line.
for I=1, string.len( TempMessage ) do
-- If the char is a '@' then check if the next char represents a color.
if string.sub( TempMessage, I, I ) == "@" then
local Char = string.sub( TempMessage, I + 1, I + 1 )
local Color = ReturnColorFromChar( TempMessage, Char )
-- If the next char represented a color then put the color in the string.
if Color ~= nil then
TempMessage = string.gsub( TempMessage, "@" .. Char, Color )
line = line:gsub("(@.)",
function(a_Str)
local Char = a_Str:sub(2, 2)
if (Char == "@") then
-- If the input was "@@" then simply replace it with a single "@"
return "@"
end

local Color = ReturnColorFromChar(Char)
if (Color) then
return Color
end
end
end
-- Add the message to the list of messages.
Messages[#Messages + 1] = TempMessage
)

table.insert(Messages, line)
end

end

function ShowMOTDTo( Player )
Expand Down

0 comments on commit 5171b43

Please sign in to comment.