~mira-dev/mira/p2p

« back to all changes in this revision

Viewing changes to mira-server/src/network/TcpConnection.cpp

  • Committer: Alan Alvarez
  • Date: 2008-08-24 20:03:46 UTC
  • mfrom: (170.1.3 mira)
  • Revision ID: alan.alvarez@us.army.mil-20080824200346-gjk9cckgxwl39esy
- Add dynamic fields to Users and WorkPlaces
- Track Users and Workplaces by IDs (unsigned int)

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
TcpConnection::~TcpConnection()
43
43
{
44
44
    if (is_logged_in())
45
 
        Application::get_server().remove_connection(m_username);
 
45
        Application::get_server().remove_connection(m_user_id);
46
46
 
47
47
    // delete peding messages in queue.
48
48
    // TODO: We might actually want to process these messages before deleting this object
158
158
        {
159
159
            // log user in and mark TcpConnection as logged in.
160
160
            string *l_message = m_message_queue.front();
161
 
            m_username = l_message->substr(2);
162
 
            size_t username_pos = m_username.find(' ');
 
161
            string username = l_message->substr(2);
 
162
            size_t username_pos = username.find(' ');
163
163
            string password;
164
 
            if (username_pos != string::npos && m_username.length() > username_pos+1)
 
164
            if (username_pos != string::npos && username.length() > username_pos+1)
165
165
            {
166
 
                password = m_username.substr(username_pos+1);
167
 
                m_username.erase(username_pos);
 
166
                password = username.substr(username_pos+1);
 
167
                username.erase(username_pos);
168
168
            }
169
169
            else
170
170
            {
173
173
                return;
174
174
            }
175
175
 
176
 
            if (Application::get_directory().login(m_username, password))
 
176
            unsigned int m_user_id = Application::get_directory().login(username, password);
 
177
            if (m_user_id)
177
178
            {
178
 
                Application::get_server().add_connection(m_username, this);
 
179
                Application::get_server().add_connection(m_user_id, this);
179
180
                send("LS");
180
181
            }
181
182
            else
205
206
            // NOTE: the pointer returned by m_message_queue.front() NEEDS to be deleted in Msg::Parse().
206
207
            //       We have to store messages as pointer to make we still have valid a object after we pop()
207
208
            //       and the worker thread is accessing the object.
208
 
            TcpConnection::m_thread_pool.add_task( boost::bind(&Msg::Parse, m_username, m_message_queue.front()) );
 
209
            TcpConnection::m_thread_pool.add_task( boost::bind(&Msg::Parse, m_user_id, m_message_queue.front()) );
209
210
            m_message_queue.pop();
210
211
        }
211
212
    }