-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #216 from cuberite/motdcleanup
Clean up MOTD code
- Loading branch information
Showing
5 changed files
with
22 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,25 @@ | ||
function HandleMOTDCommand( Split, Player ) | ||
ShowMOTDTo( Player ) | ||
return true | ||
end | ||
|
||
function LoadMotd() | ||
local MOTD = {} | ||
|
||
function LoadMOTD() | ||
-- Check if the file 'motd.txt' exists, if not, create it with default content: | ||
if (not cFile:IsFile("motd.txt")) then | ||
CreateFile = io.open( "motd.txt", "w" ) | ||
CreateFile:write("@6Welcome to the Cuberite test server!\n@6http://www.cuberite.org/\n@6Type /help for all commands") | ||
if not cFile:IsFile("motd.txt") then | ||
CreateFile = io.open("motd.txt", "w") | ||
CreateFile:write("@6Welcome to the Cuberite test server!\n@6https://cuberite.org/\n@6Type /help for all commands") | ||
CreateFile:close() | ||
end | ||
|
||
for line in io.lines( "motd.txt" ) do | ||
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 | ||
) | ||
|
||
table.insert(Messages, line) | ||
for Line in io.lines("motd.txt") do | ||
table.insert(MOTD, Line) | ||
end | ||
end | ||
|
||
function ShowMOTDTo( Player ) | ||
for I=1, #Messages do | ||
Player:SendMessage(Messages[I]) | ||
function ShowMOTD(Player) | ||
for i = 1, #MOTD do | ||
Player:SendMessage(MOTD[i]) | ||
end | ||
end | ||
|
||
function HandleMOTDCommand(Split, Player) | ||
ShowMOTD(Player) | ||
return true | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function OnPlayerJoined(Player) | ||
-- Send the MOTD to the player: | ||
ShowMOTD(Player) | ||
|
||
-- Add a message to the webadmin chat: | ||
WEBLOGINFO(Player:GetName() .. " has joined the game") | ||
end |