Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
biboumi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
90
Issues
90
List
Boards
Labels
Service Desk
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
louiz’
biboumi
Commits
3cfaab9a
Commit
3cfaab9a
authored
Nov 12, 2013
by
louiz’
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Map irc commands to callbacks, in a clean way
parent
5817a95b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
26 deletions
+28
-26
src/irc/irc_client.cpp
src/irc/irc_client.cpp
+5
-25
src/irc/irc_client.hpp
src/irc/irc_client.hpp
+23
-1
No files found.
src/irc/irc_client.cpp
View file @
3cfaab9a
...
@@ -74,31 +74,11 @@ void IrcClient::parse_in_buffer()
...
@@ -74,31 +74,11 @@ void IrcClient::parse_in_buffer()
IrcMessage
message
(
this
->
in_buf
.
substr
(
0
,
pos
));
IrcMessage
message
(
this
->
in_buf
.
substr
(
0
,
pos
));
this
->
in_buf
=
this
->
in_buf
.
substr
(
pos
+
2
,
std
::
string
::
npos
);
this
->
in_buf
=
this
->
in_buf
.
substr
(
pos
+
2
,
std
::
string
::
npos
);
std
::
cout
<<
message
<<
std
::
endl
;
std
::
cout
<<
message
<<
std
::
endl
;
// TODO map function and command name properly
auto
cb
=
irc_callbacks
.
find
(
message
.
command
);
if
(
message
.
command
==
"PING"
)
if
(
cb
!=
irc_callbacks
.
end
())
this
->
send_pong_command
(
message
);
(
this
->*
(
cb
->
second
))(
message
);
else
if
(
message
.
command
==
"NOTICE"
||
else
message
.
command
==
"375"
||
std
::
cout
<<
"No handler for command "
<<
message
.
command
<<
std
::
endl
;
message
.
command
==
"372"
)
this
->
forward_server_message
(
message
);
else
if
(
message
.
command
==
"JOIN"
)
this
->
on_channel_join
(
message
);
else
if
(
message
.
command
==
"PRIVMSG"
)
this
->
on_channel_message
(
message
);
else
if
(
message
.
command
==
"353"
)
this
->
set_and_forward_user_list
(
message
);
else
if
(
message
.
command
==
"332"
)
this
->
on_topic_received
(
message
);
else
if
(
message
.
command
==
"366"
)
this
->
on_channel_completely_joined
(
message
);
else
if
(
message
.
command
==
"001"
)
this
->
on_welcome_message
(
message
);
else
if
(
message
.
command
==
"PART"
)
this
->
on_part
(
message
);
else
if
(
message
.
command
==
"QUIT"
)
this
->
on_quit
(
message
);
else
if
(
message
.
command
==
"NICK"
)
this
->
on_nick
(
message
);
}
}
}
}
...
...
src/irc/irc_client.hpp
View file @
3cfaab9a
...
@@ -167,11 +167,33 @@ private:
...
@@ -167,11 +167,33 @@ private:
*/
*/
std
::
vector
<
std
::
string
>
channels_to_join
;
std
::
vector
<
std
::
string
>
channels_to_join
;
bool
welcomed
;
bool
welcomed
;
IrcClient
(
const
IrcClient
&
)
=
delete
;
IrcClient
(
const
IrcClient
&
)
=
delete
;
IrcClient
(
IrcClient
&&
)
=
delete
;
IrcClient
(
IrcClient
&&
)
=
delete
;
IrcClient
&
operator
=
(
const
IrcClient
&
)
=
delete
;
IrcClient
&
operator
=
(
const
IrcClient
&
)
=
delete
;
IrcClient
&
operator
=
(
IrcClient
&&
)
=
delete
;
IrcClient
&
operator
=
(
IrcClient
&&
)
=
delete
;
};
};
/**
* Define a map of functions to be called for each IRC command we can
* handle.
*/
typedef
void
(
IrcClient
::*
irc_callback_t
)(
const
IrcMessage
&
);
static
const
std
::
unordered_map
<
std
::
string
,
irc_callback_t
>
irc_callbacks
=
{
{
"NOTICE"
,
&
IrcClient
::
forward_server_message
},
{
"375"
,
&
IrcClient
::
forward_server_message
},
{
"372"
,
&
IrcClient
::
forward_server_message
},
{
"JOIN"
,
&
IrcClient
::
on_channel_join
},
{
"PRIVMSG"
,
&
IrcClient
::
on_channel_message
},
{
"353"
,
&
IrcClient
::
set_and_forward_user_list
},
{
"332"
,
&
IrcClient
::
on_topic_received
},
{
"366"
,
&
IrcClient
::
on_channel_completely_joined
},
{
"001"
,
&
IrcClient
::
on_welcome_message
},
{
"PART"
,
&
IrcClient
::
on_part
},
{
"QUIT"
,
&
IrcClient
::
on_quit
},
{
"NICK"
,
&
IrcClient
::
on_nick
},
{
"MODE"
,
&
IrcClient
::
on_mode
},
{
"PING"
,
&
IrcClient
::
send_pong_command
},
};
#endif // IRC_CLIENT_INCLUDED
#endif // IRC_CLIENT_INCLUDED
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment