-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChannel.cs
190 lines (161 loc) · 5.75 KB
/
Channel.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace System.Net.IRC.Client
{
public delegate void ChannelMessage(Server server, Channel channel, string message);
public class Channel
{
public event ChannelMessage ChannelEvent;
private string name;
private string title ="";
// private string titleCreater;
private Server server;
//private List<string> nickNames;
private List<User> nickNames;
//private List<string> messages = new List<string>();
private string messages = "";
public string Name
{
get { return this.name; }
set { this.name = value; }
}
public string Title
{
get { return this.title; }
}
public Server Server
{
get { return this.server; }
}
public string Messages
{
get { return this.messages; }
}
public List<User> NickNames
{
get { return this.nickNames; }
}
public Channel(Server server, string name)
{
this.nickNames = new List<User>();
this.server = server;
this.name = name;
}
public void Join(string username)
{
User user = new User(username);
this.nickNames.Add(user);
//this.nickNames.Sort();
this.server.ReceivedChannelCommands(this, "JOIN");
}
public void Leave(string username)
{
// this.nickNames.Remove(username);
this.server.ReceivedChannelCommands(this, "PART");
}
public void recevedCommands(string[] commandParts)
{
string commandAction = commandParts[1];
switch (commandAction)
{
case "332":
case "333": this.setTitle(commandParts); break;
case "353": this.setNickNames(commandParts); break;
case "366": break;
case "328": break;
case "JOIN": this.Join(commandParts[0]); break;
case "PART": break;
case "MODE": break;
case "NICK": break;
case "KICK": break;
case "QUIT": break;
case "PRIVMSG": this.ReceveMessage(commandParts); break;
default: this.ReceveMessage(commandParts); break;
}
}
public void setTitle(string[] commandParts)
{
if (commandParts[1] == "332")
{
string title = "";
if (commandParts[4].Substring(0, 1) == ":")
{
commandParts[4] = commandParts[4].Remove(0, 1);
}
for (int intI = 4; intI < commandParts.Length; intI++)
{
title += " " + commandParts[intI];
}
this.messages += title + " \n";
this.title += title;
this.server.ReceivedChannelMessages(this, title);
this.server.ReceivedChannelCommands(this, "TOPIC");
}
else if (commandParts[1] == "333")
{
string message = "Topic for " + this.name + " set by " + commandParts[4] + " on " + " \n";
this.messages += message;
this.server.ReceivedChannelMessages(this, message);
}
}
public void setNickNames(string[] commandParts)
{
for (int intI = 6; intI < commandParts.Length; intI++)
{
User newUser = new User(commandParts[intI]);
this.nickNames.Add(newUser);
}
//this.nickNames.Sort();
this.server.ReceivedChannelCommands(this, "NAMES");
}
public void ReceveMessage(string[] commandParts)
{
string channelMessage = "";
for (int intI = 2; intI < commandParts.Length; intI++)
{
channelMessage += " " + commandParts[intI];
}
messages += commandParts[0] + " " + channelMessage + " \n";
this.server.ReceivedChannelMessages(this, commandParts[0] + " " + channelMessage);
}
public void ReceveMessage(string user, string channelMessage)
{
messages +=user + " " + channelMessage+" \n";
this.server.ReceivedChannelMessages(this, channelMessage);
}
public void SendMessage(string message)
{
this.messages += message + "\r\n";
this.server.SentChannelMessages(this, message);
}
public void sendCommand(string command, string value, bool print)
{
if (command == "PRIVMSG")
{
this.SendMessage(value);
}
else
{
if (print == true)
{
messages += command + " " + value + " \n";
}
}
//this.server.ChannelSentMessages(this, command + " " + value + " \n");
/*if (print == true)
{
if (this.SendEvent != null)
{
this.SendEvent(this, command + " " + value);
}
messages +=(command + " " + channelMessage+" \n");
}
this.server.Writer.WriteLine(command + " " + value);
}
this.server.Writer.Flush();*/
}
}
}