Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitchell94 committed Mar 18, 2012
1 parent 84bbbcf commit 6819f66
Show file tree
Hide file tree
Showing 479 changed files with 111,848 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.metadata/*

#Visual Studio files
/bin
/obj
/Updater/bin
/Updater/obj
*.suo
*.user
*.[Cc]ache
*.bak

#OS garbage
[Tt]humbs.db
*.DS_STORE
*.lnk
116 changes: 116 additions & 0 deletions AutoSaver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCForge)
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;


namespace MCForge
{
//I
class AutoSaver
{
static int _interval;
string backupPath = @Server.backupLocation;

static int count = 1;
public AutoSaver(int interval)
{
_interval = interval * 1000;

new Thread(new ThreadStart(delegate
{
while (true)
{
Thread.Sleep(_interval);
Server.ml.Queue(delegate { Run(); });

if (Player.players.Count <= 0) continue;
string allCount = Player.players.Aggregate("", (current, pl) => current + (", " + pl.name));
try { Server.s.Log("!PLAYERS ONLINE: " + allCount.Remove(0, 2), true); }
catch { }

allCount = Server.levels.Aggregate("", (current, l) => current + (", " + l.name));
try { Server.s.Log("!LEVELS ONLINE: " + allCount.Remove(0, 2), true); }
catch { }
}
})).Start();
}

/*
static void Exec()
{
Server.ml.Queue(delegate
{
Run();
});
}*/

public static void Run()
{
try
{
count--;

Server.levels.ForEach(delegate(Level l)
{
try
{
if (!l.changed) return;
if (Server.lava.active && Server.lava.HasMap(l.name)) { l.saveChanges(); return; }

l.Save();
if (count == 0)
{
int backupNumber = l.Backup();

if (backupNumber != -1)
{
l.ChatLevel("Backup " + backupNumber + " saved.");
Server.s.Log("Backup " + backupNumber + " saved for " + l.name);
}
}
}
catch
{
Server.s.Log("Backup for " + l.name + " has caused an error.");
}
});

if (count <= 0)
{
count = 15;
}
}
catch (Exception e) { Server.ErrorLog(e); }

try
{
if (Player.players.Count > 0)
{
List<Player> tempList = new List<Player>();
tempList.AddRange(Player.players);
foreach (Player p in tempList) { p.save(); }
tempList.Clear();
}
}
catch (Exception e) { Server.ErrorLog(e); }
}
}
}
215 changes: 215 additions & 0 deletions Awards.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
/*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCForge)
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace MCForge
{
public class Awards
{
public struct playerAwards { public string playerName; public List<string> awards; }
public class awardData {
public string awardName, description;
public void setAward(string name) { awardName = camelCase(name); }
}

public static List<Awards.playerAwards> playersAwards = new List<Awards.playerAwards>();
public static List<Awards.awardData> allAwards = new List<Awards.awardData>();

public static void Load()
{
if (!File.Exists("text/awardsList.txt"))
{
using (StreamWriter SW = File.CreateText("text/awardsList.txt"))
{
SW.WriteLine("#This is a full list of awards. The server will load these and they can be awarded as you please");
SW.WriteLine("#Format is:");
SW.WriteLine("# awardName : Description of award goes after the colon");
SW.WriteLine();
SW.WriteLine("Gotta start somewhere : Built your first house");
SW.WriteLine("Climbing the ladder : Earned a rank advancement");
SW.WriteLine("Do you live here? : Joined the server a huge bunch of times");
}
}

allAwards = new List<awardData>();
foreach (string s in File.ReadAllLines("text/awardsList.txt"))
{
if (s == "" || s[0] == '#') continue;
if (s.IndexOf(" : ") == -1) continue;

awardData aD = new awardData();

aD.setAward(s.Split(new string[] { " : " }, StringSplitOptions.None)[0]);
aD.description = s.Split(new string[] { " : " }, StringSplitOptions.None)[1];

allAwards.Add(aD);
}

playersAwards = new List<playerAwards>();
if (File.Exists("text/playerAwards.txt"))
{
foreach (String s in File.ReadAllLines("text/playerAwards.txt"))
{
if (s.IndexOf(" : ") == -1) continue;

playerAwards pA;
pA.playerName = s.Split(new string[] { " : " }, StringSplitOptions.None)[0].ToLower();
string myAwards = s.Split(new string[] { " : " }, StringSplitOptions.None)[1];

pA.awards = new List<string>();
if (myAwards.IndexOf(',') != -1)
foreach (string a in myAwards.Split(','))
pA.awards.Add(camelCase(a));
else if (myAwards.Trim() != "")
pA.awards.Add(camelCase(myAwards));

playersAwards.Add(pA);
}
}

Save();
}

public static void Save()
{
using (StreamWriter SW = File.CreateText("text/awardsList.txt"))
{
SW.WriteLine("#This is a full list of awards. The server will load these and they can be awarded as you please");
SW.WriteLine("#Format is:");
SW.WriteLine("# awardName : Description of award goes after the colon");
SW.WriteLine();
foreach (awardData aD in allAwards)
SW.WriteLine(camelCase(aD.awardName) + " : " + aD.description);
}
using (StreamWriter SW = File.CreateText("text/playerAwards.txt"))
{
foreach (playerAwards pA in playersAwards)
SW.WriteLine(pA.playerName.ToLower() + " : " + string.Join(",", pA.awards.ToArray()));
}
}

public static bool giveAward(string playerName, string awardName)
{
foreach (playerAwards pA in playersAwards)
{
if (pA.playerName == playerName.ToLower())
{
if (pA.awards.Contains(camelCase(awardName)))
return false;
pA.awards.Add(camelCase(awardName));
return true;
}
}

playerAwards newPlayer;
newPlayer.playerName = playerName.ToLower();
newPlayer.awards = new List<string>();
newPlayer.awards.Add(camelCase(awardName));
playersAwards.Add(newPlayer);
return true;
}
public static bool takeAward(string playerName, string awardName)
{
foreach (playerAwards pA in playersAwards)
{
if (pA.playerName == playerName.ToLower())
{
if (!pA.awards.Contains(camelCase(awardName)))
return false;
pA.awards.Remove(camelCase(awardName));
return true;
}
}

return false;
}
public static List<string> getPlayersAwards(string playerName)
{
foreach (playerAwards pA in playersAwards)
if (pA.playerName == playerName.ToLower())
return pA.awards;

return new List<string>();
}
public static string getDescription(string awardName)
{
foreach (awardData aD in allAwards)
if (camelCase(aD.awardName) == camelCase(awardName))
return aD.description;

return "";
}
public static string awardAmount(string playerName)
{
foreach (playerAwards pA in playersAwards)
if (pA.playerName == playerName.ToLower())
return "&f" + pA.awards.Count + "/" + allAwards.Count + " (" + Math.Round((double)((double)pA.awards.Count / allAwards.Count) * 100, 2) + "%)" + Server.DefaultColor;

return "&f0/" + allAwards.Count + " (0%)" + Server.DefaultColor;
}
public static bool addAward(string awardName, string awardDescription)
{
if (awardExists(awardName)) return false;

awardData aD = new awardData();
aD.awardName = camelCase(awardName);
aD.description = awardDescription;
allAwards.Add(aD);
return true;
}
public static bool removeAward(string awardName)
{
foreach (awardData aD in allAwards)
{
if (camelCase(aD.awardName) == camelCase(awardName))
{
allAwards.Remove(aD);
return true;
}
}
return false;
}
public static bool awardExists(string awardName)
{
foreach (awardData aD in allAwards)
if (camelCase(aD.awardName) == camelCase(awardName))
return true;

return false;
}


public static string camelCase(string givenName)
{
string returnString = "";
if (givenName != "")
foreach (string s in givenName.Split(' '))
if (s.Length > 1)
returnString += s[0].ToString().ToUpper() + s.Substring(1).ToLower() + " ";
else
returnString += s.ToUpper() + " ";

return returnString.Trim();
}
}
}
Loading

1 comment on commit 6819f66

@DeveloperJose
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, I guess we're going back to Obsidian/MCSharp/MCLawl base :3

Please sign in to comment.