-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseClient.cs
More file actions
97 lines (77 loc) · 2.65 KB
/
BaseClient.cs
File metadata and controls
97 lines (77 loc) · 2.65 KB
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
using System;
using System.Collections.Generic;
namespace oftc_ircd_cs
{
public delegate bool ClientStringEventHandler(BaseClient client, string str);
public class ClientStringEventArgs : EventArgs
{
public BaseClient Client { get; private set; }
public string Str { get; private set; }
public ClientStringEventArgs(BaseClient client, string str)
{
Client = client;
Str = str;
}
}
public class BaseClient
{
private static readonly Dictionary<string, BaseClient> Names =
new Dictionary<string, BaseClient>(StringComparer.InvariantCultureIgnoreCase);
private static readonly List<BaseClient> Unregistered = new List<BaseClient>();
public string Name { get; set; }
public string Host { get; set; }
public Connection Connection { get; set; }
public AccessLevel Level { get; set; }
public DateTime FirstSeen { get; set; }
public DateTime LastData { get; set; }
public DateTime PingSent { get; set; }
public Server Server { get; set; }
public event ClientStringEventHandler NickChanging;
public static void Init()
{
var me = new Server { Name = General.Conf.ServerName, Info = General.Conf.ServerInfo };
Server.Me = me;
}
public static BaseClient FindByName(string name)
{
if (Names.ContainsKey(name))
return Names[name];
return null;
}
public static void AddName(BaseClient client)
{
Names.Add(client.Name, client);
}
public static void DeleteName(BaseClient client)
{
if (!String.IsNullOrEmpty(client.Name))
Names.Remove(client.Name);
}
public static void AddUnregistered(BaseClient client)
{
Unregistered.Add(client);
}
public static void RemoveUnregistered(BaseClient client)
{
Unregistered.Remove(client);
}
public static bool nick_changing(BaseClient client, string str)
{
return client.NickChanging == null || client.NickChanging(client, str);
}
public void Send(string message)
{
string str = message.Length > 510 ? message.Substring(0, 510) : message;
str += "\r\n";
Connection.Send(str);
}
public bool IsRegistered()
{
return Level > AccessLevel.Unregistered;
}
public override string ToString()
{
return String.IsNullOrEmpty(Name) ? "*" : Name;
}
}
}