Skip to content
This repository
Browse code

Fixes merge conflicts

  • Loading branch information...
commit 04df687bc9d6b273837291dc0afd5e90767930e9 2 parents 5f9748f + cb8ba29
iamtrulygod authored April 25, 2012
37  plugins/antenna.cpp
@@ -5,7 +5,7 @@
5 5
  *
6 6
  * broadcasts are of the format
7 7
  * [type][channel][nick][contents]
8  
- * type is a 4 byte string, currently "edct" for normal edicts, "mdct" for medicts, "ntfy" for notifies, "whhe" for who is here, "here" for here, "nick" for nick changes.
  8
+ * type is a 4 byte string, currently "edct" for normal edicts, "mdct" for medicts, "ntfy" for notifies, "whhe" for who is here, "here" for here, "nick" for nick changes, "left" for announcing you left a channel.
9 9
  * channel is a 64 byte string which contains the destination channel for the message terminated with zero characters.
10 10
  * nick is the same size and idea as channel, except it contains the nick of the sender.
11 11
  * contents is a max 256 byte string of whatever the text being sent is.  If the contents are shorter, the broadcast is shorter to match.
@@ -44,6 +44,7 @@
44 44
 #include "QHostAddress_hash.h"
45 45
 #include "nick_messages.h"
46 46
 #include "userlist_messages.h"
  47
+#include "channel_messages.h"
47 48
 
48 49
 using namespace std;
49 50
 
@@ -77,6 +78,7 @@ void run(plugin_pipe p, string name)
77 78
 	p.write(registration_message::create(0, name, "block query"));
78 79
 	p.write(registration_message::create(0, name, "changed_nick"));
79 80
 	p.write(registration_message::create(0, name, "sendable_notify"));
  81
+	p.write(registration_message::create(0, name, "leave_channel"));
80 82
 
81 83
 	p.write(register_handler::create("/block", sendBlock));
82 84
 	p.write(register_handler::create("/unblock", sendUnblock));
@@ -290,6 +292,26 @@ void run(plugin_pipe p, string name)
290 292
 
291 293
 				currentNick=castMessage->newNick;
292 294
 			}
  295
+			else if (m.type == "leave_channel")
  296
+			{
  297
+				auto castMessage=dynamic_cast<leave_channel_message *>(m.getdata());
  298
+
  299
+				//if it's not actually a here message, ignore it and move on
  300
+				if (!castMessage)
  301
+					continue;
  302
+
  303
+				QString channel = castMessage->channel;
  304
+				QString type = "left";
  305
+
  306
+				QByteArray message = formatMessage(type,channel,currentNick,"");
  307
+
  308
+				//change to use write() function when we have time
  309
+				if(message.length()>0)
  310
+				{
  311
+					udpSocket.writeDatagram(message,groupAddress,port);
  312
+					lastSent=time(NULL);
  313
+				}
  314
+			}
293 315
 			//if somehow a message is recieved that is not of these types, send it back.
294 316
 			else
295 317
 			{
@@ -311,7 +333,7 @@ void run(plugin_pipe p, string name)
311 333
 
312 334
 			if (type=="auto")
313 335
 			{
314  
-				p.write(received_message::create(received_message_subtype::HERE,"",QString::fromUtf8(broadcast+4),"",senderIP));
  336
+				p.write(received_status_message::create(received_status_message_subtype::HERE,"",QString::fromUtf8(broadcast+4),senderIP));
315 337
 				continue;
316 338
 			}
317 339
 
@@ -321,17 +343,22 @@ void run(plugin_pipe p, string name)
321 343
 
322 344
 			if (type=="whhe")
323 345
 			{
324  
-				p.write(received_message::create(received_message_subtype::WHOHERE,destinationChannel,senderNick,"",senderIP));
  346
+				p.write(received_status_message::create(received_status_message_subtype::WHOHERE,destinationChannel,senderNick,senderIP));
325 347
 				continue;
326 348
 			}
327 349
 			else if (type=="here")
328 350
 			{
329  
-				p.write(received_message::create(received_message_subtype::HERE,destinationChannel,senderNick,"",senderIP));
  351
+				p.write(received_status_message::create(received_status_message_subtype::HERE,destinationChannel,senderNick,senderIP));
330 352
 				continue;
331 353
 			}
332 354
 			else if (type=="nick")
333 355
 			{
334  
-				p.write(received_message::create(received_message_subtype::NICK,destinationChannel,senderNick,"",senderIP));
  356
+				p.write(received_status_message::create(received_status_message_subtype::NICK,destinationChannel,senderNick,senderIP));
  357
+				continue;
  358
+			}
  359
+			else if (type=="left")
  360
+			{
  361
+				p.write(received_status_message::create(received_status_message_subtype::LEFT,destinationChannel,senderNick,senderIP));
335 362
 				continue;
336 363
 			}
337 364
 
17  plugins/channel_messages.h
@@ -3,24 +3,25 @@
3 3
 
4 4
 #include <QStringList>
5 5
 
6  
-class set_channel : public message_data
  6
+class set_channel_message : public message_data
  7
+
7 8
 {
8 9
 public:
9  
-	virtual std::unique_ptr<message_data> copy() const {return std::unique_ptr<message_data>(new set_channel(*this));}
10  
-	static message create(const QString &ch) {return message_create("set_channel", new set_channel(ch));}
  10
+	virtual std::unique_ptr<message_data> copy() const {return std::unique_ptr<message_data>(new set_channel_message(*this));}
  11
+	static message create(const QString &ch) {return message_create("set_channel", new set_channel_message(ch));}
11 12
 
12  
-	set_channel(const QString &ch) : channel(ch) {}
  13
+	set_channel_message(const QString &ch) : channel(ch) {}
13 14
 
14 15
 	QString channel;
15 16
 };
16 17
 
17  
-class leave_channel : public message_data
  18
+class leave_channel_message : public message_data
18 19
 {
19 20
 public:
20  
-	virtual std::unique_ptr<message_data> copy() const {return std::unique_ptr<message_data>(new leave_channel(*this));}
21  
-	static message create(const QString &ch) {return message_create("leave_channel", new leave_channel(ch));}
  21
+	virtual std::unique_ptr<message_data> copy() const {return std::unique_ptr<message_data>(new leave_channel_message(*this));}
  22
+	static message create(const QString &ch) {return message_create("leave_channel", new leave_channel_message(ch));}
22 23
 
23  
-	leave_channel(const QString &ch) : channel(ch) {}
  24
+	leave_channel_message(const QString &ch) : channel(ch) {}
24 25
 
25 26
 	QString channel;
26 27
 };
4  plugins/meatgrinder.cpp
@@ -56,7 +56,7 @@ message handle_channel_change(QString text, QString)
56 56
 {
57 57
 	if (!text.startsWith("/channel"))
58 58
 		return empty_message::create();
59  
-	return set_channel::create(text.remove(0, 9));
  59
+	return set_channel_message::create(text.remove(0, 9));
60 60
 }
61 61
 
62 62
 message handle_commands(QString text, QString channel)
@@ -88,7 +88,7 @@ message handle_channel_leave(QString text, QString)
88 88
 {
89 89
 	if (!text.startsWith("/leave"))
90 90
 		return empty_message::create();
91  
-	return leave_channel::create(text.remove(0, 7));
  91
+	return leave_channel_message::create(text.remove(0, 7));
92 92
 }
93 93
 
94 94
 message handle_user_command(QString text, QString)
22  plugins/received_messages.h
@@ -19,7 +19,11 @@
19 19
 
20 20
 enum class received_message_subtype
21 21
 {
22  
-	NORMAL,ME,NOTIFY,HERE,WHOHERE,NICK
  22
+	NORMAL,ME,NOTIFY
  23
+};
  24
+enum class received_status_message_subtype
  25
+{
  26
+	LEFT,HERE,WHOHERE,NICK
23 27
 };
24 28
 
25 29
 
@@ -40,4 +44,20 @@ class received_message : public message_data
40 44
 	QHostAddress ipAddress;
41 45
 };
42 46
 
  47
+class received_status_message : public message_data
  48
+{
  49
+public:
  50
+	virtual std::unique_ptr<message_data> copy() const {return std::unique_ptr<message_data>(new received_status_message(*this));}
  51
+
  52
+	//received messages have three contents, the channel to display to, the nick of the sender, and the contents of the broadcast.
  53
+	static message create(received_status_message_subtype sub, const QString &chan, const QString &nik, const QHostAddress &ip) {return message_create("received_status", new received_status_message(sub,chan,nik,ip));}
  54
+
  55
+	received_status_message(received_status_message_subtype sub, const QString &chan, const QString &nik, const QHostAddress &ip) : subtype(sub), channel(chan), nick(nik), ipAddress(ip) {}
  56
+
  57
+	received_status_message_subtype subtype;
  58
+	QString channel;
  59
+	QString nick;
  60
+	QHostAddress ipAddress;
  61
+};
  62
+
43 63
 #endif // RECEIVED_MESSAGES_H
67  plugins/userlist.cpp
@@ -10,6 +10,7 @@
10 10
 #include "grinder_messages.h"
11 11
 #include "lirch_constants.h"
12 12
 #include "nick_messages.h"
  13
+#include "channel_messages.h"
13 14
 
14 15
 using namespace std;
15 16
 
@@ -46,25 +47,50 @@ message sendList(QString text, QString channel)
46 47
 }
47 48
 
48 49
 //updates all of the relevent fields of out status map based on the received message
49  
-void updateSenderStatus(plugin_pipe p, received_message * message, unordered_map<QString, user_status> & userList)
  50
+void updateSenderStatus(plugin_pipe p, message m, unordered_map<QString, user_status> & userList)
50 51
 {
51  
-	//message->channel is storing the old nickname of the user in the case that it is a nick type received.
52  
-	//if it is, remove the person of the old nickname
53  
-	if (message->subtype==received_message_subtype::NICK)
  52
+
  53
+	if (m.type=="received")
54 54
 	{
55  
-		user_status oldNickInfo = userList[message->channel];
56  
-		oldNickInfo.nick=message->nick;
57  
-		userList.erase(message->channel);
58  
-		userList[message->nick]=oldNickInfo;
59  
-		return;
  55
+		auto message=dynamic_cast<received_message *>(m.getdata());
  56
+		userList[message->nick].nick=message->nick;
  57
+		userList[message->nick].channels.insert(message->channel);
  58
+		userList[message->nick].ip=message->ipAddress;
  59
+		userList[message->nick].lastseen=time(NULL);
60 60
 	}
61 61
 
62  
-	userList[message->nick].nick=message->nick;
63  
-	if ((message->subtype==received_message_subtype::NORMAL || message->subtype==received_message_subtype::ME || message->subtype==received_message_subtype::NOTIFY) && message->channel!="")
64  
-		userList[message->nick].channels.insert(message->channel);
  62
+	if (m.type=="received_status")
  63
+	{
  64
+		auto message=dynamic_cast<received_status_message *>(m.getdata());
  65
+		userList[message->nick].lastseen=time(NULL);
  66
+		userList[message->nick].nick=message->nick;
  67
+		userList[message->nick].ip=message->ipAddress;
65 68
 
66  
-	userList[message->nick].ip=message->ipAddress;
67  
-	userList[message->nick].lastseen=time(NULL);
  69
+		if (message->subtype==received_status_message_subtype::LEFT)
  70
+		{
  71
+			userList[message->nick].channels.erase(message->channel);
  72
+			p.write(notify_message::create(message->channel,message->nick+" has left channel "+message->channel+"."));
  73
+		}
  74
+		else if (message->subtype==received_status_message_subtype::HERE)
  75
+		{
  76
+			userList[message->nick].channels.insert(message->channel);
  77
+		}
  78
+		else if (message->subtype==received_status_message_subtype::WHOHERE)
  79
+		{
  80
+			p.write(here_message::create(message->channel));
  81
+			userList[message->nick].channels.insert(message->channel);
  82
+		}
  83
+		else if (message->subtype==received_status_message_subtype::NICK)
  84
+		{
  85
+			//message->channel is storing the old nickname of the user in the case that it is a nick type received.
  86
+			//if it is, remove the person of the old nickname
  87
+			user_status oldNickInfo = userList[message->channel];
  88
+			oldNickInfo.nick=message->nick;
  89
+			userList.erase(message->channel);
  90
+			userList[message->nick]=oldNickInfo;
  91
+		}
  92
+
  93
+	}
68 94
 
69 95
 	p.write(userlist_message::create(userList));
70 96
 }
@@ -120,8 +146,10 @@ void run(plugin_pipe p, string name)
120 146
 	p.write(registration_message::create(0, name, "userlist_request"));
121 147
 	p.write(registration_message::create(0, name, "userlist_timer"));
122 148
 	p.write(registration_message::create(30000, name, "received"));
  149
+	p.write(registration_message::create(30000, name, "received_status"));
123 150
 	p.write(registration_message::create(0, name, "list_channels"));
124 151
 	p.write(registration_message::create(0, name, "handler_ready"));
  152
+	p.write(registration_message::create(0, name, "leave_channel"));
125 153
 	p.write(registration_message::create(-30000, name, "nick"));
126 154
 
127 155
 
@@ -191,17 +219,10 @@ void run(plugin_pipe p, string name)
191 219
 			p.write(register_handler::create("/list", sendList));
192 220
 			p.write(register_handler::create("/nick", sendNick));
193 221
 		}
194  
-		else if (m.type=="received")
  222
+		else if (m.type=="received" || m.type=="received_status")
195 223
 		{
196  
-			auto s=dynamic_cast<received_message *>(m.getdata());
197  
-			if (!s)
198  
-				continue;
199 224
 			p.write(m.decrement_priority());
200  
-			updateSenderStatus(p,s,userList);
201  
-			if (s->subtype==received_message_subtype::WHOHERE)
202  
-			{
203  
-				p.write(here_message::create(s->channel));
204  
-			}
  225
+			updateSenderStatus(p,m,userList);
205 226
 		}
206 227
 		else if (m.type=="nick")
207 228
 		{
4  ui/basic/basic.cpp
@@ -27,7 +27,7 @@ void send_input(plugin_pipe out, plugin_pipe in)
27 27
 			message m=in.read();
28 28
 			if (m.type=="set_channel")
29 29
 			{
30  
-				auto i=dynamic_cast<set_channel *>(m.getdata());
  30
+				auto i=dynamic_cast<set_channel_message *>(m.getdata());
31 31
 				if (i)
32 32
 					channel=i->channel;
33 33
 			}
@@ -113,7 +113,7 @@ void run(plugin_pipe p, string name)
113 113
 		}
114 114
 		else if (m.type=="set_channel")
115 115
 		{
116  
-			auto i=dynamic_cast<set_channel *>(m.getdata());
  116
+			auto i=dynamic_cast<set_channel_message *>(m.getdata());
117 117
 			if (!i)
118 118
 				continue;
119 119
 			p.write(m.decrement_priority());

0 notes on commit 04df687

Please sign in to comment.
Something went wrong with that request. Please try again.