Browse Source

minor updates to the peer/host indication, todo's added

Arnis Lielturkss 7 years ago
parent
commit
90f47055fa

+ 12 - 1
Source/Samples/54_P2PMultiplayer/P2PMultiplayer.cpp

@@ -113,6 +113,12 @@ void P2PMultiplayer::CreateUI()
     readyButton_ = CreateButton("Ready", 160, IntVector2(20, marginTop));
     marginTop += 40;
     unreadyButton_ = CreateButton("Unready", 160, IntVector2(20, marginTop));
+
+    roleTitle_ = CreateLabel("", IntVector2(GetSubsystem<Graphics>()->GetWidth() / 2, GetSubsystem<Graphics>()->GetHeight() / 2));
+    roleTitle_->SetTextAlignment(HA_CENTER);
+    roleTitle_->SetColor(Color::GREEN);
+    roleTitle_->SetFontSize(40);
+    
 //	stopServer_->SetVisible(false);
 //
 //    // Create client connection related fields
@@ -203,7 +209,7 @@ void P2PMultiplayer::HandleUpdate(StringHash eventType, VariantMap& eventData)
         body_->SetLinearVelocity(Vector3(0, 0, 0));
     }
 
-    if (timer_.GetMSec(false) > 2000) {
+    if (timer_.GetMSec(false) > 500) {
         i++;
         timer_.Reset();
 //        URHO3D_LOGINFO(" ");
@@ -218,9 +224,13 @@ void P2PMultiplayer::HandleUpdate(StringHash eventType, VariantMap& eventData)
         if (GetSubsystem<Network>()->P2PGetGUID() == GetSubsystem<Network>()->P2PGetHostAddress()) {
             hostGuid_->SetColor(Color::RED);
             myGuid_->SetColor(Color::RED);
+            roleTitle_->SetText("HOST");
+            roleTitle_->SetColor(Color::RED);
         } else {
             myGuid_->SetColor(Color::GREEN);
             hostGuid_->SetColor(Color::GREEN);
+            roleTitle_->SetText("PEER");
+            roleTitle_->SetColor(Color::GREEN);
         }
 //        URHO3D_LOGINFO("P2PGetGUID: " + GetSubsystem<Network>()->P2PGetGUID());
 //        URHO3D_LOGINFO("P2PGetHostAddress: " + GetSubsystem<Network>()->P2PGetHostAddress());
@@ -283,6 +293,7 @@ Text* P2PMultiplayer::CreateLabel(const String& text, IntVector2 pos)
     label->SetColor(Color(0.0f, 1.0f, 0.0f));
     label->SetPosition(pos);
     label->SetText(text);
+    label->SetTextEffect(TextEffect::TE_STROKE);
 	return label;
 }
 //

+ 1 - 0
Source/Samples/54_P2PMultiplayer/P2PMultiplayer.h

@@ -121,6 +121,7 @@ private:
     SharedPtr<LineEdit> guid_;
 //    /// Found server list
 	SharedPtr<Text> clientCount_;
+    SharedPtr<Text> roleTitle_;
     SharedPtr<Text> myGuid_;
     SharedPtr<Text> hostGuid_;
     SharedPtr<RigidBody> body_;

+ 12 - 6
Source/Urho3D/Network/Network.cpp

@@ -291,14 +291,17 @@ Network::Network(Context* context) :
 
 Network::~Network()
 {
+    // If server connection exists, disconnect, but do not send an event because we are shutting down
+    Disconnect(1000);
+
     fullyConnectedMesh2_->ResetHostCalculation();
+    
     rakPeer_->DetachPlugin(natPunchthroughServerClient_);
     rakPeerClient_->DetachPlugin(natPunchthroughClient_);
     rakPeer_->DetachPlugin(fullyConnectedMesh2_);
     rakPeer_->DetachPlugin(connectionGraph2_);
     rakPeer_->DetachPlugin(readyEvent_);
-    // If server connection exists, disconnect, but do not send an event because we are shutting down
-    Disconnect(100);
+
     serverConnection_.Reset();
 
     clientConnections_.Clear();
@@ -343,14 +346,16 @@ void Network::HandleMessage(const SLNet::AddressOrGUID& source, int packetID, in
         eventData[P_DATA].SetBuffer(msg.GetData(), msg.GetSize());
         connection->SendEvent(E_NETWORKMESSAGE, eventData);
     }
-    else
-        URHO3D_LOGWARNING("Discarding message from unknown MessageConnection " + String(source.ToString()) + " => " + source.rakNetGuid.ToString());
+    else {
+     //   URHO3D_LOGWARNING("Discarding message from unknown MessageConnection " + String(source.ToString()) + " => " + source.rakNetGuid.ToString());
+    }
 }
 
 void Network::NewConnectionEstablished(const SLNet::AddressOrGUID& connection)
 {
     if (clientConnections_[connection]) {
         URHO3D_LOGWARNINGF("Client already in the client list.", connection.rakNetGuid.ToString());
+        //TODO proper scene state management
         clientConnections_[connection]->SetSceneLoaded(true);
         return;
     }
@@ -836,7 +841,9 @@ void Network::HandleIncomingPacket(SLNet::Packet* packet, bool isServer)
     }
     else if (packetID == ID_REMOTE_CONNECTION_LOST)
     {
-        ClientDisconnected(packet->guid);
+        //TODO find out who's really sending out this message
+        URHO3D_LOGWARNING("ID_REMOTE_CONNECTION_LOST");
+        //ClientDisconnected(packet->guid);
         packetHandled = true;
     }
     else if (packetID == ID_ALREADY_CONNECTED)
@@ -1448,7 +1455,6 @@ void Network::HandleTcpResponse()
                 data[HttpRequestFinished::P_ADDRESS] = "123";
                 data[HttpRequestFinished::P_RESPONSE] = String(responseReceived.C_String() + contentOffset);
                 SendEvent(E_HTTPREQUESTFINISHED, data);
-                URHO3D_LOGINFO("Response got: " + String(responseReceived.C_String() + contentOffset));
             }
         }
     }