コード例 #1
0
ファイル: Chat.cpp プロジェクト: 3dicc/Urho3D
void Chat::HandleNetworkMessage(StringHash eventType, VariantMap& eventData)
{
    Network* network = GetSubsystem<Network>();
    
    using namespace NetworkMessage;
    
    int msgID = eventData[P_MESSAGEID].GetInt();
    if (msgID == MSG_CHAT)
    {
        const PODVector<unsigned char>& data = eventData[P_DATA].GetBuffer();
        // Use a MemoryBuffer to read the message data so that there is no unnecessary copying
        MemoryBuffer msg(data);
        String text = msg.ReadString();
        
        // If we are the server, prepend the sender's IP address and port and echo to everyone
        // If we are a client, just display the message
        if (network->IsServerRunning())
        {
            Connection* sender = static_cast<Connection*>(eventData[P_CONNECTION].GetPtr());
            
            text = sender->ToString() + " " + text;
            
            VectorBuffer sendMsg;
            sendMsg.WriteString(text);
            // Broadcast as in-order and reliable
            network->BroadcastMessage(MSG_CHAT, true, true, sendMsg);
        }
        
        ShowChatText(text);
    }
}
コード例 #2
0
ファイル: DecalSet.cpp プロジェクト: TheComet93/Urho3D
PODVector<unsigned char> DecalSet::GetDecalsAttr() const
{
    VectorBuffer ret;

    ret.WriteBool(skinned_);
    ret.WriteVLE(decals_.Size());

    for (List<Decal>::ConstIterator i = decals_.Begin(); i != decals_.End(); ++i)
    {
        ret.WriteFloat(i->timer_);
        ret.WriteFloat(i->timeToLive_);
        ret.WriteVLE(i->vertices_.Size());
        ret.WriteVLE(i->indices_.Size());

        for (PODVector<DecalVertex>::ConstIterator j = i->vertices_.Begin(); j != i->vertices_.End(); ++j)
        {
            ret.WriteVector3(j->position_);
            ret.WriteVector3(j->normal_);
            ret.WriteVector2(j->texCoord_);
            ret.WriteVector4(j->tangent_);
            if (skinned_)
            {
                for (unsigned k = 0; k < 4; ++k)
                    ret.WriteFloat(j->blendWeights_[k]);
                for (unsigned k = 0; k < 4; ++k)
                    ret.WriteUByte(j->blendIndices_[k]);
            }
        }

        for (PODVector<unsigned short>::ConstIterator j = i->indices_.Begin(); j != i->indices_.End(); ++j)
            ret.WriteUShort(*j);
    }

    if (skinned_)
    {
        ret.WriteVLE(bones_.Size());

        for (Vector<Bone>::ConstIterator i = bones_.Begin(); i != bones_.End(); ++i)
        {
            ret.WriteString(i->name_);
            ret.WriteUByte(i->collisionMask_);
            if (i->collisionMask_ & BONECOLLISION_SPHERE)
                ret.WriteFloat(i->radius_);
            if (i->collisionMask_ & BONECOLLISION_BOX)
                ret.WriteBoundingBox(i->boundingBox_);
            ret.Write(i->offsetMatrix_.Data(), sizeof(Matrix3x4));
        }
    }

    return ret.GetBuffer();
}
コード例 #3
0
ファイル: ScriptInstance.cpp プロジェクト: acremean/urho3d
PODVector<unsigned char> ScriptInstance::GetDelayedMethodCallsAttr() const
{
    VectorBuffer buf;
    buf.WriteVLE(delayedMethodCalls_.Size());
    for (Vector<DelayedMethodCall>::ConstIterator i = delayedMethodCalls_.Begin(); i != delayedMethodCalls_.End(); ++i)
    {
        buf.WriteFloat(i->period_);
        buf.WriteFloat(i->delay_);
        buf.WriteBool(i->repeat_);
        buf.WriteString(i->declaration_);
        buf.WriteVariantVector(i->parameters_);
    }
    return buf.GetBuffer();
}
コード例 #4
0
ファイル: Chat.cpp プロジェクト: 3dicc/Urho3D
void Chat::HandleSend(StringHash eventType, VariantMap& eventData)
{
    String text = textEdit_->GetText();
    if (text.Empty())
        return; // Do not send an empty message
    
    Network* network = GetSubsystem<Network>();
    Connection* serverConnection = network->GetServerConnection();
    
    if (serverConnection)
    {
        // A VectorBuffer object is convenient for constructing a message to send
        VectorBuffer msg;
        msg.WriteString(text);
        // Send the chat message as in-order and reliable
        serverConnection->SendMessage(MSG_CHAT, true, true, msg);
        // Empty the text edit after sending
        textEdit_->SetText(String::EMPTY);
    }
}
void GameEconomicServerClientConsole::SendMessage(String Message)
{
    /// If sending message is empty
    if (Message.Empty())
    {
        return; // Do not send an empty message
    }

    /// Get connection
    Network* network = GetSubsystem<Network>();
    Connection* serverConnection = network->GetServerConnection();

    /// Send message only if serverconnection and connection is true
    if (serverConnection&&serverconnection)
    {
               // A VectorBuffer object is convenient for constructing a message to send
        VectorBuffer msg;
        msg.WriteString(Message);
        // Send the chat message as in-order and reliable
        serverConnection->SendMessage(NetMessageAdminClientSend, true, true, msg);
    }

    return;
}