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