-
Notifications
You must be signed in to change notification settings - Fork 13
/
Data.cs
121 lines (98 loc) · 5.37 KB
/
Data.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenSMO {
public static class Data {
public static Hashtable GetSong(string Name, string Artist, string SubTitle) {
Hashtable[] resCheck = MySql.Query("SELECT * FROM songs WHERE Name='" + Name + "' " +
"AND Artist='" + Artist + "' " +
"AND SubTitle='" + SubTitle + "'");
if (resCheck == null) return null;
if (resCheck.Length == 1)
return resCheck[0];
else
return null;
}
public static Hashtable AddSong(bool Start, User user) {
if (user.CurrentRoom == null || user.CurrentRoom.CurrentSong == null || user.CurrentRoom.Reported)
return null;
string Name = MySql.AddSlashes(user.CurrentRoom.CurrentSong.Name);
string Artist = MySql.AddSlashes(user.CurrentRoom.CurrentSong.Artist);
string SubTitle = MySql.AddSlashes(user.CurrentRoom.CurrentSong.SubTitle);
Hashtable song = Data.GetSong(Name, Artist, SubTitle);
if (user.ShadowBanned) {
if (song != null) {
return song;
} else {
Hashtable ret = new Hashtable();
ret["ID"] = -1;
ret["Name"] = Name;
ret["Artist"] = Artist;
ret["SubTitle"] = SubTitle;
ret["Played"] = 0;
ret["Notes"] = 0;
return ret;
}
}
if (song == null) {
MySql.Query("INSERT INTO songs (Name,Artist,SubTitle) VALUES(" +
"'" + Name + "'," +
"'" + Artist + "'," +
"'" + SubTitle + "')");
return MySql.Query("SELECT * FROM songs ORDER BY ID DESC LIMIT 0,1")[0];
} else if (Start) {
MySql.Query("UPDATE songs SET Played=Played+1 WHERE ID=" + song["ID"].ToString());
user.CurrentRoom.Reported = true;
}
return song;
}
public static string BanUser(User user, int originID) {
string IP = user.tcpClient.Client.RemoteEndPoint.ToString().Split(':')[0];
MySql.Query("INSERT INTO bans (IP,From) VALUES(\'" + IP + "\'," + originID + ")");
return IP;
}
public static bool IsBanned(string IP) {
Hashtable[] res = MySql.Query("SELECT * FROM bans WHERE IP = \'" + MySql.AddSlashes(IP) + "\'");
return res.Length != 0;
}
public static void AddStats(User user) {
if (user.CurrentRoom == null)
return;
if (user.CurrentRoom.CurrentSong == null)
return;
user.CurrentRoom.Status = RoomStatus.Ready;
string Name = MySql.AddSlashes(user.CurrentRoom.CurrentSong.Name);
string Artist = MySql.AddSlashes(user.CurrentRoom.CurrentSong.Artist);
string SubTitle = MySql.AddSlashes(user.CurrentRoom.CurrentSong.SubTitle);
int songID = 0;
Hashtable song = Data.GetSong(Name, Artist, SubTitle);
if (song != null) {
songID = (int)song["ID"];
if (!user.ShadowBanned) {
double songTime = user.SongTime.Elapsed.TotalSeconds;
if (songTime > (int)song["Time"]) {
MySql.Query("UPDATE songs SET Time=" + songTime.ToString().Replace(',', '.') + " WHERE ID=" + song["ID"]);
}
}
string playerSettings = MySql.AddSlashes(user.GamePlayerSettings);
// Big-ass query right there...
if (!user.ShadowBanned) {
MySql.Query("INSERT INTO stats (User,PlayerSettings,Song,Feet,Difficulty,Grade,Score,MaxCombo," +
"Note_0,Note_1,Note_Mine,Note_Miss,Note_Barely,Note_Good,Note_Great,Note_Perfect,Note_Flawless,Note_NG,Note_Held) VALUES(" +
user.User_Table["ID"].ToString() + ",'" + playerSettings + "'," + songID.ToString() + "," + user.GameFeet.ToString() + "," + ((int)user.GameDifficulty).ToString() + "," + ((int)user.Grade).ToString() + "," + user.Score.ToString() + "," + user.MaxCombo.ToString() + "," +
user.Notes[0].ToString() + "," + user.Notes[1].ToString() + "," + user.Notes[2].ToString() + "," + user.Notes[3].ToString() + "," + user.Notes[4].ToString() + "," + user.Notes[5].ToString() + "," + user.Notes[6].ToString() + "," + user.Notes[7].ToString() + "," + user.Notes[8].ToString() + "," + user.Notes[9].ToString() + "," + user.Notes[10].ToString() + ")");
}
}
// Give player XP
int XP = 0;
for (int i = 3; i <= 8; i++)
XP += (i - 3) * user.Notes[i];
XP /= 6;
user.SendChatMessage("You gained " + Func.ChatColor("aaaa00") + XP.ToString() + Func.ChatColor("ffffff") + " XP!");
if (!user.ShadowBanned)
MySql.Query("UPDATE users SET XP=XP+" + XP.ToString() + " WHERE ID=" + user.User_ID.ToString());
}
}
}