-
Notifications
You must be signed in to change notification settings - Fork 2
/
TCman.cs
198 lines (184 loc) · 8.45 KB
/
TCman.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System.Collections.Generic;
using TShockAPI;
using TShockAPI.DB;
namespace TerraClans
{
public class TCman
{
public static void CMDtcman(CommandArgs args)
{
//tcman add "clan name" "leader" "group"
if (args.Parameters.Count == 4)
{
if (args.Player.Group.HasPermission("manageclans"))
{
if (args.Parameters[0] == "add")
{
TCAdd(args);
}
else
{
args.Player.SendMessage("TerraClans:", Color.Red);
args.Player.SendMessage("/tcman add <clanname> <leader> <group> - adds clan.", Color.Red);
args.Player.SendMessage("/tcman del <clanname> - deletes clan.", Color.Red);
}
}
}
else if (args.Parameters.Count == 2)
{
if (args.Player.Group.HasPermission("manageclans"))
{
if (args.Parameters[0] == "del")
{
TCdel(args);
}
else
{
args.Player.SendMessage("TerraClans:", Color.Red);
args.Player.SendMessage("/tcman add <clanname> <leader> <group> - adds clan.", Color.Red);
args.Player.SendMessage("/tcman del <clanname> - deletes clan.", Color.Red);
}
}
}
else
{
args.Player.SendMessage("TerraClans:", Color.Red);
args.Player.SendMessage("/tcman add <clanname> <leader> <group> - adds clan.", Color.Red);
args.Player.SendMessage("/tcman del <clanname> - deletes clan.", Color.Red);
}
}
public static void TCAdd(CommandArgs incArgs)
{
bool error = false;
var DBQuery = TCdb.DB.QueryReader("SELECT clangroup FROM Clans WHERE clangroup='" + incArgs.Parameters[3] + "'");
List<string> existedGroup = new List<string>();
while (DBQuery.Read())
{
existedGroup.Add(DBQuery.Get<string>("clangroup"));
}
DBQuery = TCdb.DB.QueryReader("SELECT clanname FROM Clans WHERE clanname='" + incArgs.Parameters[1] + "'");
List<string> existedClan = new List<string>();
while (DBQuery.Read())
{
existedClan.Add(DBQuery.Get<string>("clanname"));
}
List<Player> players = new List<Player>();
players = TCutils.GetPlayersByName(incArgs.Parameters[2]);
if (players.Count == 0)
{
incArgs.Player.SendMessage("Player " + incArgs.Parameters[2] + " doesn't exist!", Color.Red);
error = true;
}
else
{
var leader = players[0].TSPlayer.IsLoggedIn;
if (!leader)
{
incArgs.Player.SendMessage("Player " + incArgs.Parameters[2] + " is not logged in!", Color.Red);
error = true;
}
else if (TCutils.AlreadyInClan(players[0].TSPlayer.UserAccountName))
{
incArgs.Player.SendMessage("One of " + incArgs.Parameters[2] + "'s characters is alredy in clan!", Color.Red);
error = true;
}
List<string> invites = new List<string>();
invites = TCutils.GetAllInvites();
foreach (string pl in invites)
{
if (pl == TCutils.GetPlayersByName(incArgs.Parameters[2])[0].TSPlayer.UserAccountName)
{
incArgs.Player.SendMessage(incArgs.Parameters[2] + " is already invited to another clan!", Color.Red);
error = true;
}
}
}
var group = TShock.Groups.GroupExists(incArgs.Parameters[3]);
if (existedGroup.Count > 0)
{
incArgs.Player.SendMessage("Group " + incArgs.Parameters[3] + " is already bound to another clan!", Color.Red);
error = true;
}
if (existedClan.Count > 0)
{
incArgs.Player.SendMessage("Clan " + incArgs.Parameters[1] + " is already exist!", Color.Red);
error = true;
}
List<string> strQueue = TCutils.InQueue(incArgs.Parameters[1], TCutils.GetPlayersByName(incArgs.Parameters[2])[0], TCutils.GetPlayersByName(incArgs.Parameters[2])[0]);
if (strQueue.Count > 0)
{
incArgs.Player.SendMessage("Clan name is occupied or player is gonna found his own clan.", Color.Red);
error = true;
}
if (!error)
{
if (!group)
{
TShock.Groups.AddGroup(incArgs.Parameters[3], "default", "");
incArgs.Player.SendMessage("Creating new group: " + incArgs.Parameters[3], Color.LawnGreen);
}
else
{
List<string> perms = new List<string>();
perms = TShock.Utils.GetGroup(incArgs.Parameters[3]).permissions;
//perms.Add("clanchat");
incArgs.Player.SendMessage("Binding clan to existing group: " + incArgs.Parameters[3], Color.LawnGreen);
TShock.Groups.AddPermissions(incArgs.Parameters[3], perms);
}
TCdb.DB.QueryReader("INSERT INTO Clans (clanname, clangroup, leaders, members, motd, invites) VALUES ('" + incArgs.Parameters[1] + "', '" + incArgs.Parameters[3] + "', '" + players[0].TSPlayer.UserAccountName + "', '', 'Welcome to " + incArgs.Parameters[1] + "!', '')");
incArgs.Player.SendMessage("Added clan: " + incArgs.Parameters[1], Color.LawnGreen);
var user = new User();
user.Name = players[0].TSPlayer.UserAccountName;
if (!players[0].TSPlayer.Group.HasPermission("terraclans"))
{
TShock.Users.SetUserGroup(user, incArgs.Parameters[3]);
}
players[0].TSPlayer.SendMessage(incArgs.Player.Name + " created clan \"" + incArgs.Parameters[1] + "\" with you as leader!", Color.YellowGreen);
players[0].TSPlayer.SendMessage("Please, relogin to apply new settings for your account.", Color.Orange);
}
}
public static void TCdel(CommandArgs incArgs)
{
string clName = "";
string clGroup = "";
var DBQuery = TCdb.DB.QueryReader("SELECT clanname, clangroup FROM Clans WHERE clanname='" + incArgs.Parameters[1] + "'");
while (DBQuery.Read())
{
clName = DBQuery.Get<string>("clanname");
clGroup = DBQuery.Get<string>("clangroup");
}
if (clName == "")
{
incArgs.Player.SendMessage("Clan \"" + incArgs.Parameters[1] + "\" doesn't exist!", Color.Red);
return;
}
List<string> clMembers = TCutils.GetMembers(clName);
List<string> clLeaders = TCutils.GetLeaders(clName);
foreach (string i in clMembers)
{
var user = new User();
user.Name = i;
string gr = TShock.Users.GetUserByName(i).Group;
if (!TShock.Utils.GetGroup(gr).HasPermission("terraclans"))
{
TShock.Users.SetUserGroup(user, TShock.Config.DefaultRegistrationGroupName);
}
}
string initPl = "";
foreach (string i in clLeaders)
{
var user = new User();
user.Name = i;
initPl = i;
string gr = TShock.Users.GetUserByName(i).Group;
if (!TShock.Utils.GetGroup(gr).HasPermission("terraclans"))
{
TShock.Users.SetUserGroup(user, TShock.Config.DefaultRegistrationGroupName);
}
}
TCutils.ClanMsg(initPl, "Your clan has been disbanded by " + incArgs.Player.Name + "!", 1, false);
TCdb.DB.QueryReader("DELETE FROM Clans WHERE clanname = '" + clName + "'");
TShock.Groups.DeleteGroup(clGroup);
}
}
}