Просмотр исходного кода

linter errors fixed, MSG_IDENTITY flows updated for p2p

Arnis Lielturks 7 лет назад
Родитель
Сommit
d286526a46

+ 6 - 3
Source/Samples/54_P2PMultiplayer/P2PMultiplayer.cpp

@@ -167,7 +167,9 @@ void P2PMultiplayer::SubscribeToEvents()
 void P2PMultiplayer::HandleStartP2PSession(StringHash eventType, VariantMap& eventData)
 {
     URHO3D_LOGINFO("HandleStartP2PSession");
-    GetSubsystem<Network>()->P2PStartSession(scene_);
+    VariantMap identity;
+    identity["Name"] = "Initial Host";
+    GetSubsystem<Network>()->P2PStartSession(scene_, identity);
     httpRequest_ = GetSubsystem<Network>()->MakeHttpRequest("http://frameskippers.com:82/?guid=" + GetSubsystem<Network>()->P2PGetGUID());
 
     SubscribeToEvent(E_P2PSESSIONSTARTED, URHO3D_HANDLER(P2PMultiplayer, HandleSessionStarted));
@@ -176,7 +178,9 @@ void P2PMultiplayer::HandleStartP2PSession(StringHash eventType, VariantMap& eve
 void P2PMultiplayer::HandleJoinP2PSession(StringHash eventType, VariantMap& eventData)
 {
     URHO3D_LOGINFO("HandleJoinP2PSession " + guid_->GetText());
-    GetSubsystem<Network>()->P2PJoinSession(guid_->GetText(), scene_);
+    VariantMap identity;
+    identity["Name"] = "Client";
+    GetSubsystem<Network>()->P2PJoinSession(guid_->GetText(), scene_, identity);
 //    GetSubsystem<Network>()->SetSimulatedLatency(Random(10.0f));
 //    GetSubsystem<Network>()->SetSimulatedLatency(10 + Random(100));
 }
@@ -485,7 +489,6 @@ void P2PMultiplayer::HandleClientDisconnected(StringHash eventType, VariantMap&
 
 void P2PMultiplayer::UpdateClientObjects()
 {
-    URHO3D_LOGWARNING("UpdateClientObjects");
     PODVector<Node*> playerNodes;
     scene_->GetNodesWithTag(playerNodes, "Player");
     auto clients = GetSubsystem<Network>()->GetClientConnections();

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

@@ -127,7 +127,7 @@ private:
     SharedPtr<Text> hostGuid_;
     String message_;
     SharedPtr<HttpRequest> httpRequest_;
-    bool _allReady;
+    bool _allReady{};
 
     HashMap<Connection*, SharedPtr<Peer>> peers_;
 };

+ 2 - 2
Source/Samples/54_P2PMultiplayer/Peer.cpp

@@ -85,7 +85,7 @@ void Peer::HandlePhysicsPrestep(StringHash eventType, VariantMap& eventData)
     }
 
     Quaternion rotation(0.0f, controls_.yaw_, 0.0f);
-    RigidBody* body = node_->GetComponent<RigidBody>();
+    auto body = node_->GetComponent<RigidBody>();
     // Movement torque is applied before each simulation step, which happen at 60 FPS. This makes the simulation
     // independent from rendering framerate. We could also apply forces (which would enable in-air control),
     // but want to emphasize that it's a ball which should only control its motion by rolling along the ground
@@ -102,7 +102,7 @@ void Peer::HandlePhysicsPrestep(StringHash eventType, VariantMap& eventData)
         body->ApplyTorque(rotation * Vector3::BACK * MOVE_TORQUE);
     }
 
-    Text3D* text = node_->GetComponent<Text3D>();
+    auto text = node_->GetComponent<Text3D>();
     if (text) {
         text->SetText(connection_->GetGUID() + " [" + String(connection_->GetLastPing()) + "]");
     }

+ 2 - 0
Source/Urho3D/Network/Connection.cpp

@@ -918,6 +918,8 @@ void Connection::ProcessIdentity(int msgID, MemoryBuffer& msg)
     eventData[P_ALLOW] = true;
     SendEvent(E_CLIENTIDENTITY, eventData);
 
+    URHO3D_LOGERROR("Name: " + identity_["Name"].GetString());
+
     // If connection was denied as a response to the identity event, disconnect now
     if (!eventData[P_ALLOW].GetBool())
         Disconnect();

+ 13 - 13
Source/Urho3D/Network/Network.cpp

@@ -901,15 +901,15 @@ void Network::HandleIncomingPacket(SLNet::Packet* packet, bool isServer)
                 rakPeer_->Send(&bsOut, HIGH_PRIORITY, RELIABLE_ORDERED, 0, packet->guid, false);
 
                 //TODO send out our identity
-//                {
-//                    VectorBuffer msg;
-//                    msg.WriteVariantMap(serverConnection_->GetIdentity());
-//
-//                    VectorBuffer buffer;
-//                    buffer.WriteUByte((unsigned char)MSG_IDENTITY);
-//                    buffer.Write(msg.GetData(), msg.GetSize());
-//                    rakPeer_->Send((const char *) buffer.GetData(), (int) buffer.GetSize(), HIGH_PRIORITY, RELIABLE_ORDERED, (char) 0, packet->guid, false);
-//                }
+                {
+                    VectorBuffer msg;
+                    msg.WriteVariantMap(serverConnection_->GetIdentity());
+
+                    VectorBuffer buffer;
+                    buffer.WriteUByte((unsigned char)MSG_IDENTITY);
+                    buffer.Write(msg.GetData(), msg.GetSize());
+                    rakPeer_->Send((const char *) buffer.GetData(), (int) buffer.GetSize(), HIGH_PRIORITY, RELIABLE_ORDERED, (char) 0, packet->guid, false);
+                }
 
             }
         }
@@ -968,7 +968,7 @@ void Network::HandleIncomingPacket(SLNet::Packet* packet, bool isServer)
             URHO3D_LOGINFO("Connecting to server behind NAT: " + String(remotePeer.ToString()));
             Connect(String(remotePeer.ToString(false)), remotePeer.GetPort(), scene_, identity_);
         } else if (networkMode_ == PEER_TO_PEER){
-            SLNet::ConnectionAttemptResult car = rakPeer_->Connect(packet->systemAddress.ToString(false), packet->systemAddress.GetPort(), 0, 0);
+            SLNet::ConnectionAttemptResult car = rakPeer_->Connect(packet->systemAddress.ToString(false), packet->systemAddress.GetPort(), password_.CString(), password_.Length());
         }
         packetHandled = true;
     }
@@ -1117,14 +1117,14 @@ void Network::HandleIncomingPacket(SLNet::Packet* packet, bool isServer)
     else if (packetID == ID_FCM2_VERIFIED_JOIN_CAPABLE)
     {
         URHO3D_LOGINFO("ID_FCM2_VERIFIED_JOIN_CAPABLE");
-        fullyConnectedMesh2_->RespondOnVerifiedJoinCapable(packet, true, 0);
+        fullyConnectedMesh2_->RespondOnVerifiedJoinCapable(packet, true, nullptr);
         packetHandled = true;
     }
     else if (packetID == ID_FCM2_VERIFIED_JOIN_ACCEPTED)
     {
         DataStructures::List<SLNet::RakNetGUID> systemsAccepted;
         bool thisSystemAccepted;
-        fullyConnectedMesh2_->GetVerifiedJoinAcceptedAdditionalData(packet, &thisSystemAccepted, systemsAccepted, 0);
+        fullyConnectedMesh2_->GetVerifiedJoinAcceptedAdditionalData(packet, &thisSystemAccepted, systemsAccepted, nullptr);
         if (thisSystemAccepted) {
             URHO3D_LOGINFO("Game join request accepted");
         }
@@ -1392,7 +1392,7 @@ void Network::HandleNATStartP2PSession(StringHash eventType, VariantMap& eventDa
     SendEvent(E_P2PSESSIONSTARTED);
 }
 
-void Network::P2PJoinSession(String guid, Scene* scene, const VariantMap& identity)
+void Network::P2PJoinSession(const String guid, Scene* scene, const VariantMap& identity)
 {
     if (!natPunchServerAddress_) {
         URHO3D_LOGERROR("Set the NAT server info first!");

+ 1 - 1
Source/Urho3D/Network/Network.h

@@ -76,7 +76,7 @@ public:
     /// Start P2P session
     bool P2PStartSession(Scene* scene, const VariantMap& identity = Variant::emptyVariantMap);
     /// Join existing P2P session
-    void P2PJoinSession(String guid, Scene* scene, const VariantMap& identity = Variant::emptyVariantMap);
+    void P2PJoinSession(const String guid, Scene* scene, const VariantMap& identity = Variant::emptyVariantMap);
     /// Current peer count in session
     int GetP2PParticipantCount();
     /// Is host connected to the P2P session