NETPLAY : yet some fixing. now connections work and chatting *should* work. still crashes when game starts (probably some wxString::format bug AGAIN >_> ) some bugs still remain but the bugs i know should now be noted with TODO or NOTE

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4003 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
daco65 2009-08-16 11:36:31 +00:00
parent 86e585a66a
commit 193a36b918
2 changed files with 23 additions and 14 deletions

View File

@ -103,9 +103,7 @@ void *ServerSide::Entry()
for (char i = 0; i < nbSocketReady; ++i) for (char i = 0; i < nbSocketReady; ++i)
{ {
m_CriticalSection.Enter(); m_CriticalSection.Enter();
sf::SocketTCP Socket = m_selector.GetSocketReady(i); sf::SocketTCP Socket = m_selector.GetSocketReady(i);
if (Socket == m_socket) if (Socket == m_socket)
{ {
// Incoming connection // Incoming connection
@ -134,7 +132,6 @@ void *ServerSide::Entry()
// Add it to the selector // Add it to the selector
m_selector.Add(Incoming); m_selector.Add(Incoming);
Event->SendEvent(HOST_NEWPLAYER); Event->SendEvent(HOST_NEWPLAYER);
m_numplayers++; m_numplayers++;
} }
else else
@ -264,10 +261,16 @@ bool ServerSide::SyncValues(unsigned char socketnb, sf::IPAddress Address)
{ {
// Test UDP Socket Receive, 2s timeout // Test UDP Socket Receive, 2s timeout
if (!RecvT(m_socketUDP, (char*)&init_number, 1, received, 2)) if (!RecvT(m_socketUDP, (char*)&init_number, 1, received, 2))
{
ERROR_LOG(NETPLAY,"Connection to client timed out or closed");
errorUDP = true; errorUDP = true;
}
} }
else else
{
ERROR_LOG(NETPLAY,"Failed to send info! closing connection!");
errorUDP = true; errorUDP = true;
}
// Check if the client has the game // Check if the client has the game
Socket.Receive((char *)&init_number, 1, received); Socket.Receive((char *)&init_number, 1, received);
@ -293,12 +296,12 @@ bool ServerSide::SyncValues(unsigned char socketnb, sf::IPAddress Address)
m_client[i].socket.Send(m_client[socketnb].nick.c_str(), buffer_size + 1); m_client[i].socket.Send(m_client[socketnb].nick.c_str(), buffer_size + 1);
} }
} }
Event->AppendText( wxString::FromAscii((wxT("*Connection established to %s (%s:%d)\n"),
Event->AppendText( wxString::Format(wxT("*Connection established to %s (%s:%d)\n"), m_client[socketnb].nick.c_str(), Address.ToString().c_str(), m_client[m_numplayers].port)) );
m_client[socketnb].nick.c_str(), Address.ToString().c_str(), m_client[m_numplayers].port) );
if (init_number != 0x1F) // Not Found if (init_number != 0x1F) // Not Found
for (int i = 0; i < 4; i++) //for (int i = 0; i < 4; i++)
//note for sl1nk3 : what is that for doing there?
Event->AppendText(_("WARNING : Game Not Found on Client Side !\n")); Event->AppendText(_("WARNING : Game Not Found on Client Side !\n"));
// UDP connecton successful // UDP connecton successful
@ -405,12 +408,14 @@ void *ClientSide::Entry()
unsigned char value; unsigned char value;
size_t val_sz; size_t val_sz;
m_socket.Receive((char *)&value, 1, val_sz); m_socket.Receive((char *)&value, 1, val_sz);
// TODO : fix it. for some odd reason value is 1 instead of 16 making the connection "not successfull"
if (value == 0x16) // UDP connection successful if (value == 0x16) // UDP connection successful
{ {
Event->AppendText(_("Connection successful !\n")); Event->AppendText(_("Connection successful !\n"));
Event->AppendText( wxString::Format(wxT("*Connection established to %s (%s)\n*Game is : %s\n"), // note by DacoTaco : i hate to do this...
m_hostnick.c_str(), m_addr.c_str(), m_selectedgame.c_str() ) ); // TODO : make it better. old wxString::Format method crashed for some odd reason
std::string temp = "*Connection established to " + m_hostnick + "(" + m_addr + ")\n*Game is : " +
m_selectedgame + "\n ";
Event->AppendText( wxString::FromAscii( temp.c_str() ) );
} }
else else
{ {
@ -503,6 +508,8 @@ bool ClientSide::SyncValues()
m_socket.Receive((char *)&m_netmodel, 4, recv_size); m_socket.Receive((char *)&m_netmodel, 4, recv_size);
// Send client's UDP Port // Send client's UDP Port
// TODO : fix port sending. it sends the set port in the main window. not the actual using port
// when checked to use random this will , ofcourse , send wrong port
m_socket.Send((const char *)&m_port, sizeof(short)); m_socket.Send((const char *)&m_port, sizeof(short));
// Send client's nickname // Send client's nickname
@ -528,7 +535,10 @@ bool ClientSide::SyncValues()
{ {
// Test UDP Socket Receive, 2s timeout // Test UDP Socket Receive, 2s timeout
if (!RecvT(m_socketUDP, (char*)&byterecv, 1, recv_size, 2)) if (!RecvT(m_socketUDP, (char*)&byterecv, 1, recv_size, 2))
{
errorUDP = true; errorUDP = true;
ERROR_LOG(NETPLAY,"Connection Timed Out or closed");
}
} }
else else
errorUDP = true; errorUDP = true;

View File

@ -360,9 +360,7 @@ void NetPlay::UpdateNetWindow(bool update_infos, wxString infos)
{ {
m_critical.Enter(); m_critical.Enter();
//m_Game_str->SetLabel(wxString::Format(wxT(" Game : %s"), m_selectedGame.c_str())); //m_Game_str->SetLabel(wxString::Format(wxT(" Game : %s"), m_selectedGame.c_str()));
//Note By Daco : i'd hate to make another variable... (they take up space :( ) m_Game_str->SetLabel(wxString::FromAscii( ( wxT( "Game %s"), m_selectedGame.c_str() )));
std::string temp = " Game : " + m_selectedGame;
m_Game_str->SetLabel(wxString::FromAscii( temp.c_str() ));
m_critical.Leave(); m_critical.Leave();
} }
} }
@ -459,7 +457,8 @@ void NetPlay::OnGUIEvent(wxCommandEvent& event)
case ID_CHAT: case ID_CHAT:
{ {
value = 0x30; value = 0x30;
wxString chat_str = wxString::Format(wxT("> %s : %s\n"), m_nick.c_str(), m_Chat->GetValue().c_str()); // TODO : there seems to be a random bug here that i can't reproduce... looked like a loop bug :/
wxString chat_str = wxString::Format(wxT("> %s : %s\n"), wxString(m_nick.c_str(), wxConvUTF8).c_str() , m_Chat->GetValue().c_str() );
int chat_size = (int)chat_str.size(); int chat_size = (int)chat_str.size();
// If there's no distant connection, we write but we don't send // If there's no distant connection, we write but we don't send