Couldn't find wdiff. Falling back to builtin diff colouring...
| host.hpp | | host.hpp | |
| | | | |
| skipping to change at line 85 | | skipping to change at line 85 | |
| user* self; | | user* self; | |
| }; | | }; | |
| | | | |
| typedef basic_host<selector> host; | | typedef basic_host<selector> host; | |
| | | | |
| template<typename selector_type> | | template<typename selector_type> | |
| basic_host<selector_type>::basic_host(const std::string& username, bool ipv
6) | | basic_host<selector_type>::basic_host(const std::string& username, bool ipv
6) | |
| : basic_object<selector_type>(), | | : basic_object<selector_type>(), | |
| basic_local<selector_type>(), | | basic_local<selector_type>(), | |
| basic_server<selector_type>(ipv6), | | basic_server<selector_type>(ipv6), | |
|
| self(new user(++ basic_server<selector_type>::id_counter, NULL) ) | | self(new user(1, NULL) ) | |
| { | | { | |
| self->login(username); | | self->login(username); | |
| basic_object<selector_type>::user_add(self); | | basic_object<selector_type>::user_add(self); | |
| } | | } | |
| | | | |
| template<typename selector_type> | | template<typename selector_type> | |
| basic_host<selector_type>:: | | basic_host<selector_type>:: | |
| basic_host(unsigned int port, const std::string& username, bool ipv6
) | | basic_host(unsigned int port, const std::string& username, bool ipv6
) | |
| : basic_object<selector_type>(), | | : basic_object<selector_type>(), | |
| basic_local<selector_type>(), | | basic_local<selector_type>(), | |
| basic_server<selector_type>(port, ipv6), | | basic_server<selector_type>(port, ipv6), | |
|
| self(new user(++ basic_server<selector_type>::id_counter, NULL) ) | | self(new user(1, NULL) ) | |
| { | | { | |
| self->login(username); | | self->login(username); | |
| basic_object<selector_type>::user_add(self); | | basic_object<selector_type>::user_add(self); | |
| } | | } | |
| | | | |
| template<typename selector_type> | | template<typename selector_type> | |
| void basic_host<selector_type>::send(const packet& pack) | | void basic_host<selector_type>::send(const packet& pack) | |
| { | | { | |
| basic_server<selector_type>::send(pack); | | basic_server<selector_type>::send(pack); | |
| } | | } | |
| | | | |
End of changes. 2 change blocks. |
| 2 lines changed or deleted | | 2 lines changed or added | |
|
| server.hpp | | server.hpp | |
| | | | |
| skipping to change at line 228 | | skipping to change at line 228 | |
| packet& pack); | | packet& pack); | |
| virtual void on_data(const user& user, | | virtual void on_data(const user& user, | |
| const packet& pack); | | const packet& pack); | |
| | | | |
| virtual void net_client_login(user& from, const packet& pack); | | virtual void net_client_login(user& from, const packet& pack); | |
| | | | |
| std::auto_ptr<tcp_server_socket> serv_sock; | | std::auto_ptr<tcp_server_socket> serv_sock; | |
| std::auto_ptr<tcp_server_socket> serv6_sock; | | std::auto_ptr<tcp_server_socket> serv6_sock; | |
| | | | |
| bool use_ipv6; | | bool use_ipv6; | |
|
| unsigned int id_counter; | | | |
| | | | |
| dh_params params; | | dh_params params; | |
| | | | |
| signal_connect_type signal_connect; | | signal_connect_type signal_connect; | |
| signal_disconnect_type signal_disconnect; | | signal_disconnect_type signal_disconnect; | |
| signal_join_type signal_join; | | signal_join_type signal_join; | |
| signal_part_type signal_part; | | signal_part_type signal_part; | |
| signal_login_auth_type signal_login_auth; | | signal_login_auth_type signal_login_auth; | |
| signal_login_type signal_login; | | signal_login_type signal_login; | |
| signal_login_extend_type signal_login_extend; | | signal_login_extend_type signal_login_extend; | |
| | | | |
| skipping to change at line 250 | | skipping to change at line 249 | |
| | | | |
| private: | | private: | |
| void shutdown_impl(); | | void shutdown_impl(); | |
| void reopen_impl(unsigned int port, bool use_ipv6); | | void reopen_impl(unsigned int port, bool use_ipv6); | |
| }; | | }; | |
| | | | |
| typedef basic_server<selector> server; | | typedef basic_server<selector> server; | |
| | | | |
| template<typename selector_type> | | template<typename selector_type> | |
| basic_server<selector_type>::basic_server(bool ipv6) | | basic_server<selector_type>::basic_server(bool ipv6) | |
|
| : id_counter(0), use_ipv6(ipv6) | | : use_ipv6(ipv6) | |
| { | | { | |
| } | | } | |
| | | | |
| template<typename selector_type> | | template<typename selector_type> | |
| basic_server<selector_type>::basic_server(unsigned int port, bool ipv6) | | basic_server<selector_type>::basic_server(unsigned int port, bool ipv6) | |
|
| : id_counter(0), use_ipv6(ipv6) | | : use_ipv6(ipv6) | |
| { | | { | |
| reopen_impl(port, ipv6); | | reopen_impl(port, ipv6); | |
| } | | } | |
| | | | |
| template<typename selector_type> | | template<typename selector_type> | |
| basic_server<selector_type>::~basic_server() | | basic_server<selector_type>::~basic_server() | |
| { | | { | |
| // TODO: Call user_clear first to remove user connections first? | | // TODO: Call user_clear first to remove user connections first? | |
| if(is_open() ) | | if(is_open() ) | |
| shutdown_impl(); | | shutdown_impl(); | |
| | | | |
| skipping to change at line 411 | | skipping to change at line 410 | |
| packet pack("net6_client_part"); | | packet pack("net6_client_part"); | |
| pack << user_id; | | pack << user_id; | |
| send(pack); | | send(pack); | |
| } | | } | |
| } | | } | |
| | | | |
| template<typename selector_type> | | template<typename selector_type> | |
| void basic_server<selector_type>::on_accept_event(tcp_server_socket& sock, | | void basic_server<selector_type>::on_accept_event(tcp_server_socket& sock, | |
| io_condition io) | | io_condition io) | |
| { | | { | |
|
| | | // Find a unique user ID | |
| | | unsigned int last_id = 0; | |
| | | for(typename basic_object<selector_type>::user_map::iterator iter =
this->users.begin(); iter != this->users.end(); ++iter) | |
| | | { | |
| | | if(iter->second->get_id() != last_id + 1) | |
| | | break; | |
| | | last_id = iter->second->get_id(); | |
| | | } | |
| | | | |
| // Get selector from base class | | // Get selector from base class | |
| selector_type& selector = basic_object<selector_type>::get_selector(
); | | selector_type& selector = basic_object<selector_type>::get_selector(
); | |
| connection_type* conn = new connection_type(selector); | | connection_type* conn = new connection_type(selector); | |
|
| std::auto_ptr<user> client(new user(++ id_counter, conn) ); | | std::auto_ptr<user> client(new user(last_id + 1, conn) ); | |
| | | | |
| conn->recv_event().connect( | | conn->recv_event().connect( | |
| sigc::bind( | | sigc::bind( | |
| sigc::mem_fun(*this, &basic_server::on_recv_event), | | sigc::mem_fun(*this, &basic_server::on_recv_event), | |
| sigc::ref(*client) | | sigc::ref(*client) | |
| ) | | ) | |
| ); | | ); | |
| | | | |
| conn->close_event().connect( | | conn->close_event().connect( | |
| sigc::bind( | | sigc::bind( | |
| | | | |
| skipping to change at line 565 | | skipping to change at line 573 | |
| net_client_login(user& user, const packet& pack) | | net_client_login(user& user, const packet& pack) | |
| { | | { | |
| // Is already logged in | | // Is already logged in | |
| if(user.is_logged_in() ) return; | | if(user.is_logged_in() ) return; | |
| | | | |
| // Get wished user name | | // Get wished user name | |
| // TODO: trim name? | | // TODO: trim name? | |
| const std::string& name = | | const std::string& name = | |
| pack.get_param(0).parameter::as<std::string>(); | | pack.get_param(0).parameter::as<std::string>(); | |
| | | | |
|
| | | login::error reason; | |
| | | | |
| // Check for valid user name | | // Check for valid user name | |
| if(name.empty() ) | | if(name.empty() ) | |
| { | | { | |
| packet pack("net6_login_failed"); | | packet pack("net6_login_failed"); | |
| pack << static_cast<int>(login::ERROR_NAME_INVALID); | | pack << static_cast<int>(login::ERROR_NAME_INVALID); | |
| send(pack, user); | | send(pack, user); | |
| } | | } | |
|
| | | // Check for login_auth | |
| | | else if(!on_login_auth(user, pack, reason)) | |
| | | { | |
| | | packet pack("net6_login_failed"); | |
| | | pack << static_cast<int>(reason); | |
| | | send(pack, user); | |
| | | return; | |
| | | } | |
| // Check for existing user name | | // Check for existing user name | |
| else if(basic_object<selector_type>::user_find(name) != NULL) | | else if(basic_object<selector_type>::user_find(name) != NULL) | |
| { | | { | |
| packet pack("net6_login_failed"); | | packet pack("net6_login_failed"); | |
| pack << static_cast<int>(login::ERROR_NAME_IN_USE); | | pack << static_cast<int>(login::ERROR_NAME_IN_USE); | |
| send(pack, user); | | send(pack, user); | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| // Check for login_auth | | | |
| login::error reason; | | | |
| if(!on_login_auth(user, pack, reason) ) | | | |
| { | | | |
| packet pack("net6_login_failed"); | | | |
| pack << static_cast<int>(reason); | | | |
| send(pack, user); | | | |
| return; | | | |
| } | | | |
| | | | |
| // Login succeeded | | // Login succeeded | |
| user.login(name); | | user.login(name); | |
| on_login(user, pack); | | on_login(user, pack); | |
| | | | |
| // Synchronise with other clients | | // Synchronise with other clients | |
| packet self_pack("net6_client_join"); | | packet self_pack("net6_client_join"); | |
| self_pack << user.get_id() << name << user.is_encrypted(); | | self_pack << user.get_id() << name << user.is_encrypted(); | |
| on_login_extend(user, self_pack); | | on_login_extend(user, self_pack); | |
| send(self_pack, user); | | send(self_pack, user); | |
| | | | |
| | | | |
End of changes. 8 change blocks. |
| 14 lines changed or deleted | | 22 lines changed or added | |
|