-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWCellUtil.cs
113 lines (102 loc) · 2.98 KB
/
WCellUtil.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
using System;
using IRCAddon;
using WCell.RealmServer;
using WCell.RealmServer.Commands;
using WCell.Intercommunication.DataTypes;
using Squishy.Irc;
using WCell.Util.Commands;
using IRCAddon.Commands;
using WCellStr = WCell.Util.Strings.StringStream;
namespace WCellAddon.IRCAddon
{
public static class WCellUtil
{
/// <summary>
/// Maps AuthNames of the IRC-network to ingame Account names.
/// Should be saved to/loaded from a file.
/// Should be maintainable of People with high enough priv levels (check Role.IsAdmin)
/// </summary>
/// <summary>
/// Adds an AuthResolved handler
/// </summary>
/// <param name="irc"></param>
public static void Init(IrcClient irc)
{
irc.AuthMgr.AuthResolved += usr =>
{
if (!RealmServer.Instance.AuthClient.IsConnected)
{
usr.Msg("AuthServer is offline, authentication disabled.");
return;
}
var acc = GetAccount(usr.AuthName);
if (acc != null)
{
var wcellUser = new WCellUser(acc, usr);
var args = new WCellArgs(acc);
usr.Args = args;
if (args.Account.Role >= RoleStatus.Staff)
{
args.CmdArgs = new RealmServerCmdArgs(wcellUser, false, null);
}
}
else
{
// User cannot use commands because he does not have a verified Account
// maybe send him a link to register online
usr.Msg("You do not have sufficient rights");
}
};
}
/// <summary>
/// Returns the Account of the User with the given authName.
/// </summary>
/// <param name="authName"></param>
/// <returns></returns>
public static RealmAccount GetAccount(string authName)
{
var accName = GetAccName(authName);
return accName != null
? RealmServer.Instance.GetOrRequestAccount(accName)
: null;
}
public static string GetAccName(string authName)
{
string accName;
AccountAssociationsList.AccAssDict.TryGetValue(authName, out accName);
return accName;
}
public static bool HandleCommand(WCellUser wcellUser, IrcUser user, IrcChannel chan, string text)
{
var uArgs = user.Args as WCellArgs;
if (uArgs != null)
{
if (uArgs.Account.Role >= RoleStatus.Staff)
{
var cmdArgs = uArgs.CmdArgs;
var trigger = new WCellCmdTrigger(wcellUser, chan, new WCellStr(text), cmdArgs);
bool isDouble;
RealmCommandHandler.ConsumeCommandPrefix(trigger.Text, out isDouble);
trigger.Args.Double = isDouble;
// init the trigger and check if the given args are valid
if (trigger.InitTrigger())
{
RealmCommandHandler.Instance.ExecuteInContext(trigger, OnExecuted, OnFail);
}
return true;
}
}
return false;
}
public static bool CommandExists(string alias)
{
return RealmCommandHandler.Instance.Get(alias) != null;
}
private static void OnExecuted(CmdTrigger<RealmServerCmdArgs> obj)
{
}
private static void OnFail(CmdTrigger<RealmServerCmdArgs> obj)
{
}
}
}