mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Now with less LINQ usage.
This commit is contained in:
parent
438af7cd01
commit
384596f7f8
@ -17,7 +17,6 @@
|
||||
*/
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using MCGalaxy.Commands.CPE;
|
||||
using MCGalaxy.Commands.World;
|
||||
|
||||
|
@ -91,7 +91,7 @@ namespace MCGalaxy {
|
||||
|
||||
using (StreamWriter w = new StreamWriter("text/playerAwards.txt")) {
|
||||
foreach (PlayerAward pA in PlayerAwards)
|
||||
w.WriteLine(pA.Name.ToLower() + " : " + string.Join(",", pA.Awards.ToArray()));
|
||||
w.WriteLine(pA.Name.ToLower() + " : " + pA.Awards.Join(","));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
@ -17,10 +17,9 @@
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
namespace MCGalaxy.Games {
|
||||
|
||||
|
||||
namespace MCGalaxy.Games {
|
||||
public sealed partial class CountdownGame : IGame {
|
||||
|
||||
public override void PlayerJoinedGame(Player p) {
|
||||
|
@ -17,11 +17,9 @@
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace MCGalaxy.Games {
|
||||
|
||||
namespace MCGalaxy.Games {
|
||||
public sealed partial class CountdownGame {
|
||||
|
||||
public List<Player> players = new List<Player>();
|
||||
|
@ -345,7 +345,7 @@ namespace MCGalaxy.Games
|
||||
}
|
||||
|
||||
if (OnVoteStart != null)
|
||||
OnVoteStart(votes.Keys.ToList().ToArray());
|
||||
OnVoteStart(GetVotedLevels().ToArray());
|
||||
map.ChatLevel("Vote for the next map! The vote ends in " + voteTime + " minute" + (voteTime == 1 ? "" : "s") +".");
|
||||
map.ChatLevel("Choices: " + str.Remove(0, 4));
|
||||
|
||||
@ -353,8 +353,7 @@ namespace MCGalaxy.Games
|
||||
voteTimer.AutoReset = false;
|
||||
voteTimer.Elapsed += delegate
|
||||
{
|
||||
try
|
||||
{
|
||||
try {
|
||||
EndVote();
|
||||
voteTimer.Dispose();
|
||||
}
|
||||
@ -363,9 +362,16 @@ namespace MCGalaxy.Games
|
||||
voteTimer.Start();
|
||||
voteActive = true;
|
||||
}
|
||||
|
||||
List<string> GetVotedLevels() {
|
||||
var keys = votes.Keys;
|
||||
List<string> names = new List<string>();
|
||||
foreach (string key in keys)
|
||||
names.Add(key);
|
||||
return names;
|
||||
}
|
||||
|
||||
public void EndVote()
|
||||
{
|
||||
public void EndVote() {
|
||||
if (!voteActive) return;
|
||||
|
||||
voteActive = false;
|
||||
|
@ -166,19 +166,18 @@ namespace MCGalaxy {
|
||||
int foundStart = tableSQLString.IndexOf("(") + 1;
|
||||
int foundLength = tableSQLString.LastIndexOf(")") - foundStart;
|
||||
tableSQLString = tableSQLString.Substring(foundStart, foundLength);
|
||||
|
||||
// Now we have everything inside the parenthisies.
|
||||
string[] column = tableSQLString.Split(',');
|
||||
foreach (string col in column)
|
||||
{
|
||||
if (!col.ToUpper().StartsWith("PRIMARY KEY"))
|
||||
{
|
||||
foreach (string col in column) {
|
||||
if (!col.ToUpper().StartsWith("PRIMARY KEY")) {
|
||||
bool autoInc = col.IndexOf("AUTOINCREMENT") >= 0 || col.IndexOf("AUTO_INCREMENT") >= 0;
|
||||
string[] split = col.TrimStart('\n', '\r', '\t').Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
|
||||
//Just to make it the same as the MySQL schema.
|
||||
schema.Add(new string[] { split[0].Trim('`'), split[1].Trim('\t', '`'),
|
||||
( split.Length > 2 ? (split[2].Trim('\t', '`').ToUpper() == "NOT" ? "NOT NULL" : "DEFAULT NULL") : ""),
|
||||
( split.Length > 2 ? (split[split.Length - 2].Trim('\t', '`').ToUpper() == "PRIMARY" && split[split.Length - 1].Trim('\t', '`').ToUpper() == "KEY" ? "PRI" : "") : ""),
|
||||
"NULL",
|
||||
(split.Contains("AUTO_INCREMENT") || split.Contains("AUTOINCREMENT") ? "AUTO_INCREMENT" : "")});
|
||||
"NULL", autoInc ? "AUTO_INCREMENT" : ""});
|
||||
}
|
||||
}
|
||||
return schema;
|
||||
|
@ -20,14 +20,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace MCGalaxy
|
||||
{
|
||||
public static class ProfanityFilter
|
||||
{
|
||||
namespace MCGalaxy {
|
||||
public static class ProfanityFilter {
|
||||
private static Dictionary<string, string> RegexReduce;
|
||||
private static List<string> BadWords;
|
||||
public static void Init()
|
||||
|
@ -16,13 +16,10 @@
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using MCGalaxy.Games;
|
||||
using MCGalaxy.SQL;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace MCGalaxy {
|
||||
@ -161,13 +158,17 @@ namespace MCGalaxy {
|
||||
|
||||
public static string SendResponse(HttpListenerRequest request) {
|
||||
try {
|
||||
string api = "";
|
||||
API API = new API();
|
||||
API.max_players = (int)Server.players;
|
||||
API.players = Player.players.Select(mc => mc.name).ToArray();
|
||||
API.chat = Player.Last50Chat.ToArray();
|
||||
api = JsonConvert.SerializeObject(API, Formatting.Indented);
|
||||
return api;
|
||||
API data = new API();
|
||||
data.max_players = (int)Server.players;
|
||||
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
string[] names = new string[players.Length];
|
||||
for (int i = 0; i < players.Length; i++)
|
||||
names[i] = players[i].name;
|
||||
data.players = names;
|
||||
|
||||
data.chat = Player.Last50Chat.ToArray();
|
||||
return JsonConvert.SerializeObject(data, Formatting.Indented);
|
||||
} catch(Exception e) {
|
||||
Logger.WriteError(e);
|
||||
}
|
||||
@ -177,19 +178,19 @@ namespace MCGalaxy {
|
||||
public static string WhoIsResponse(HttpListenerRequest request) {
|
||||
try {
|
||||
string p = request.QueryString.Get("name");
|
||||
if (p == null || p == "")
|
||||
return "Error";
|
||||
var whois = new WhoWas(p);
|
||||
Group grp = Group.Find(whois.rank);
|
||||
whois.banned = grp != null && grp.Permission == LevelPermission.Banned;
|
||||
if (p == null || p == "") return "Error";
|
||||
|
||||
if (whois.banned) {
|
||||
WhoWas data = new WhoWas(p);
|
||||
Group grp = Group.Find(data.rank);
|
||||
data.banned = grp != null && grp.Permission == LevelPermission.Banned;
|
||||
|
||||
if (data.banned) {
|
||||
string[] bandata = Ban.GetBanData(p);
|
||||
whois.banned_by = bandata[0];
|
||||
whois.ban_reason = bandata[1];
|
||||
whois.banned_time = bandata[2];
|
||||
data.banned_by = bandata[0];
|
||||
data.ban_reason = bandata[1];
|
||||
data.banned_time = bandata[2];
|
||||
}
|
||||
return JsonConvert.SerializeObject(whois, Formatting.Indented);
|
||||
return JsonConvert.SerializeObject(data, Formatting.Indented);
|
||||
} catch(Exception e) {
|
||||
Logger.WriteError(e);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user