12
12
#include < mutex>
13
13
#include < condition_variable>
14
14
#include < string>
15
-
16
15
#ifdef WIN32
17
16
#define HIGHLIGHT (__O__ ) std::cout<<__O__<<std::endl
18
17
#define EM (__O__ ) std::cout<<__O__<<std::endl
@@ -72,7 +71,7 @@ socket::ptr current_socket;
72
71
73
72
void bind_events (socket::ptr &socket)
74
73
{
75
- current_socket->on (" new message" , [&](string const & name, message::ptr const & data, bool isAck,message::ptr &ack_resp)
74
+ current_socket->on (" new message" ,(sio::socket::event_listener_aux) [&](string const & name, message::ptr const & data, bool isAck,message::ptr &ack_resp)
76
75
{
77
76
_lock.lock ();
78
77
string user = data->get_map ()[" username" ]->get_string ();
@@ -81,7 +80,7 @@ void bind_events(socket::ptr &socket)
81
80
_lock.unlock ();
82
81
});
83
82
84
- current_socket->on (" user joined" , [&](string const & name, message::ptr const & data, bool isAck,message::ptr &ack_resp)
83
+ current_socket->on (" user joined" , (sio::socket::event_listener_aux) [&](string const & name, message::ptr const & data, bool isAck,message::ptr &ack_resp)
85
84
{
86
85
_lock.lock ();
87
86
string user = data->get_map ()[" username" ]->get_string ();
@@ -92,7 +91,7 @@ void bind_events(socket::ptr &socket)
92
91
HIGHLIGHT (user<<" joined" <<" \n there" <<(plural?" are " :" 's " )<< participants<<(plural?" participants" :" participant" ));
93
92
_lock.unlock ();
94
93
});
95
- current_socket->on (" user left" , [&](string const & name, message::ptr const & data, bool isAck,message::ptr &ack_resp)
94
+ current_socket->on (" user left" ,(sio::socket::event_listener_aux) [&](string const & name, message::ptr const & data, bool isAck,message::ptr &ack_resp)
96
95
{
97
96
_lock.lock ();
98
97
string user = data->get_map ()[" username" ]->get_string ();
@@ -108,7 +107,7 @@ MAIN_FUNC
108
107
109
108
sio::client h;
110
109
connection_listener l (h);
111
- current_socket = h. socket ();
110
+
112
111
h.set_open_listener (std::bind (&connection_listener::on_connected, &l));
113
112
h.set_close_listener (std::bind (&connection_listener::on_close, &l,std::placeholders::_1));
114
113
h.set_fail_listener (std::bind (&connection_listener::on_fail, &l));
@@ -119,14 +118,15 @@ MAIN_FUNC
119
118
_cond.wait (_lock);
120
119
}
121
120
_lock.unlock ();
121
+ current_socket = h.socket ();
122
122
Login:
123
123
string nickname;
124
124
while (nickname.length () == 0 ) {
125
125
HIGHLIGHT (" Type your nickname:" );
126
126
127
127
getline (cin, nickname);
128
128
}
129
- current_socket->on (" login" , [&](string const & name, message::ptr const & data, bool isAck,message::ptr &ack_resp){
129
+ current_socket->on (" login" , (sio::socket::event_listener_aux) [&](string const & name, message::ptr const & data, bool isAck,message::ptr &ack_resp){
130
130
_lock.lock ();
131
131
participants = data->get_map ()[" numUsers" ]->get_int ();
132
132
bool plural = participants !=1 ;
0 commit comments