Yeah, sorry about that. I will try and make it work with the sample now. The code is a bit messy, but here it is:
Client.cpp
[code]#include “Client.h”
#include “Camera.h”
#include “CoreEvents.h”
#include “NetworkEvents.h”
#include “Octree.h”
#include “Renderer.h”
#include “Zone.h”
Client::Client(Context * context) : Object(context), context_(context), network_(new Network(context)), clientScene_(new Scene(context))
{
clientScene_->Clear(true, false);
connected_ = false;
SubscribeToEvent(E_NETWORKMESSAGE, HANDLER(Client, HandleNetworkMessage));
clientScene_->CreateComponent();
Zone * temp = clientScene_->CreateChild()->CreateComponent();
temp->SetFogColor(Color::WHITE);
input_ = context->GetSubsystem();
Camera * cam = clientScene_->CreateChild()->CreateComponent();
// Camera * cam = controlledNode_->CreateComponent(LOCAL);
// Renderer * r = GetSubsystem();
GetSubsystem<Renderer>()->SetViewport(0, new Viewport(context_, clientScene_, cam));
}
Client::~Client()
{
}
bool Client::Connect(String IP, int port = 7346)
{
connected_ = network_->Connect(IP, port, clientScene_);
connection_ = network_->GetServerConnection();
if (connection_)
{
//connection_->SetScene()
}
//clientScene_->CreateComponent(LOCAL);
//Zone * temp = clientScene_->CreateChild()->CreateComponent();
//temp->SetFogColor(Color::WHITE);
return connected_;
}
void Client::Disconnect()
{
}
void Client::HandleNetworkMessage(StringHash eventType, VariantMap& eventData)
{
//assigning node
//connection_->SetScene()
if (eventData[NetworkMessage::P_MESSAGEID].GetInt() == 31)
{
VectorBuffer b = eventData[NetworkMessage::P_DATA].GetBuffer();
controlledNode_ = clientScene_->GetNode(b.ReadUInt());
//CreateCamera();
}
}
void Client::CreateCamera()
{
Camera * cam = clientScene_->CreateChild()->CreateComponent();
// Camera * cam = controlledNode_->CreateComponent(LOCAL);
// Renderer * r = GetSubsystem();
GetSubsystem()->SetViewport(0, new Viewport(context_, clientScene_, cam));
}[/code]
Server.cpp
[code]#include “Server.h”
#include “CoreEvents.h”
#include “File.h”
#include “FileSystem.h”
#include “NetworkEvents.h”
#include “Octree.h”
#include “PhysicsWorld.h”
#include “Zone.h”
Server::Server(Context * context) : Object(context), context_(context), network_(new Network(context)), serverScene_(new Scene(context))
{
SubscribeToEvent(E_UPDATE, HANDLER(Server, HandleInput));
SubscribeToEvent(E_CLIENTCONNECTED, HANDLER(Server, HandleConnection));
Zone * temp = serverScene_->CreateChild()->CreateComponent();
temp->SetFogColor(Color::BLUE);
}
Server::~Server()
{
}
void Server::InitializeScene(XMLElement Scene, bool CreateOtherComponents)
{
if (CreateOtherComponents)
{
serverScene_->CreateComponent();
serverScene_->CreateComponent();
}
serverScene_->InstantiateXML(Scene, Vector3::ZERO, Quaternion());
File saveFile(context_, GetSubsystem()->GetProgramDir() + “SERVERSCENE.xml”, FILE_WRITE);
serverScene_->SaveXML(saveFile);
}
bool Server::InitializeServer(int port = 7346)
{
return network_->StartServer(port);
}
void Server::HandleInput(StringHash eventType, VariantMap& eventData)
{
Vector<SharedPtr>& connections = network_->GetClientConnections();
for (int i = 0; i < connections.Size(); ++i)
{
Connection * currentConnection = connections[i];
PlayerController * currentController = controllernodes[currentConnection]->GetComponent();
}
}
void Server::HandleConnection(StringHash eventType, VariantMap& eventData)
{
//This creates the player controller and adds the connection to it.
Node * controllernode = PlayerController::CreatePlayer(Vector3::ZERO, serverScene_);
//PlayerController * controller = controllernode->GetComponent();
Connection * connection = static_cast<Connection*>(eventData[ClientConnected::P_CONNECTION].GetPtr());
// connection->SetScene(serverScene_);
controllernodes[connection] = controllernode;
VectorBuffer message;
message.WriteUInt(controllernode->GetID());
connection->SendMessage(31, true, true, message);
}[/code]
Edit: Just checked, it loads fine in the scene replication demo. I guess its a problem with my code then.