Skip to content

Commit 70565d0

Browse files
committed
fix(usermessages): Send
1 parent 8815bca commit 70565d0

File tree

1 file changed

+42
-44
lines changed

1 file changed

+42
-44
lines changed

src/plugins/core/scripting/usermessage.cpp

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,12 @@ PluginUserMessage::PluginUserMessage(std::string msgname)
7676
if (!msg)
7777
return;
7878

79-
NetMessageInfo_t *msginfo = msg->GetNetMessageInfo();
79+
NetMessageInfo_t* msginfo = msg->GetNetMessageInfo();
8080
if (!msginfo)
8181
return;
8282

8383
this->msgid = msginfo->m_MessageId;
84-
auto cnetmsg = msg->AllocateMessage();
85-
this->msgBuffer = cnetmsg->ToPB<google::protobuf::Message>();
86-
delete cnetmsg;
84+
this->msgBuffer = msg->AllocateMessage()->ToPB<google::protobuf::Message>();
8785
this->internalMsg = msg;
8886
}
8987

@@ -117,8 +115,8 @@ bool PluginUserMessage::HasField(std::string pszFieldName)
117115
return false;
118116

119117
GETCHECK_FIELD(false)
120-
CHECK_FIELD_NOT_REPEATED(false)
121-
return this->msgBuffer->GetReflection()->HasField(*this->msgBuffer, field);
118+
CHECK_FIELD_NOT_REPEATED(false)
119+
return this->msgBuffer->GetReflection()->HasField(*this->msgBuffer, field);
122120
}
123121
int32 PluginUserMessage::GetInt32(std::string pszFieldName)
124122
{
@@ -549,7 +547,7 @@ std::string PluginUserMessage::GetString(std::string pszFieldName)
549547

550548
return this->msgBuffer->GetReflection()->GetString(*this->msgBuffer, field);
551549
}
552-
void PluginUserMessage::SetString(std::string pszFieldName, const char *value)
550+
void PluginUserMessage::SetString(std::string pszFieldName, const char* value)
553551
{
554552
GETCHECK_FIELD();
555553
CHECK_FIELD_TYPE_VOID(STRING);
@@ -567,7 +565,7 @@ std::string PluginUserMessage::GetRepeatedString(std::string pszFieldName, int i
567565
std::string scratch;
568566
return this->msgBuffer->GetReflection()->GetRepeatedStringReference(*this->msgBuffer, field, index, &scratch);
569567
}
570-
void PluginUserMessage::SetRepeatedString(std::string pszFieldName, int index, const char *value)
568+
void PluginUserMessage::SetRepeatedString(std::string pszFieldName, int index, const char* value)
571569
{
572570
GETCHECK_FIELD();
573571
CHECK_FIELD_TYPE_VOID(STRING);
@@ -576,7 +574,7 @@ void PluginUserMessage::SetRepeatedString(std::string pszFieldName, int index, c
576574

577575
this->msgBuffer->GetReflection()->SetRepeatedString(this->msgBuffer, field, index, value);
578576
}
579-
void PluginUserMessage::AddString(std::string pszFieldName, const char *value)
577+
void PluginUserMessage::AddString(std::string pszFieldName, const char* value)
580578
{
581579
GETCHECK_FIELD();
582580
CHECK_FIELD_TYPE_VOID(STRING);
@@ -590,17 +588,17 @@ Color PluginUserMessage::GetColor(std::string pszFieldName)
590588
CHECK_FIELD_TYPE(MESSAGE, Color(0, 0, 0, 0));
591589
CHECK_FIELD_NOT_REPEATED(Color(0, 0, 0, 0));
592590

593-
const CMsgRGBA *msgRGBA = (const CMsgRGBA *)&this->msgBuffer->GetReflection()->GetMessage(*this->msgBuffer, field);
591+
const CMsgRGBA* msgRGBA = (const CMsgRGBA*)&this->msgBuffer->GetReflection()->GetMessage(*this->msgBuffer, field);
594592

595593
return Color(msgRGBA->r(), msgRGBA->g(), msgRGBA->b(), msgRGBA->a());
596594
}
597-
void PluginUserMessage::SetColor(std::string pszFieldName, const Color &value)
595+
void PluginUserMessage::SetColor(std::string pszFieldName, const Color& value)
598596
{
599597
GETCHECK_FIELD();
600598
CHECK_FIELD_TYPE_VOID(MESSAGE);
601599
CHECK_FIELD_NOT_REPEATED();
602600

603-
CMsgRGBA *msgRGBA = (CMsgRGBA *)this->msgBuffer->GetReflection()->MutableMessage(this->msgBuffer, field);
601+
CMsgRGBA* msgRGBA = (CMsgRGBA*)this->msgBuffer->GetReflection()->MutableMessage(this->msgBuffer, field);
604602
msgRGBA->set_r(value.r());
605603
msgRGBA->set_g(value.g());
606604
msgRGBA->set_b(value.b());
@@ -613,29 +611,29 @@ Color PluginUserMessage::GetRepeatedColor(std::string pszFieldName, int index)
613611
CHECK_FIELD_REPEATED(Color(0, 0, 0, 0));
614612
CHECK_REPEATED_ELEMENT(index, Color(0, 0, 0, 0));
615613

616-
const CMsgRGBA &msgRGBA = (const CMsgRGBA &)this->msgBuffer->GetReflection()->GetRepeatedMessage(*this->msgBuffer, field, index);
614+
const CMsgRGBA& msgRGBA = (const CMsgRGBA&)this->msgBuffer->GetReflection()->GetRepeatedMessage(*this->msgBuffer, field, index);
617615
return Color(msgRGBA.r(), msgRGBA.g(), msgRGBA.b(), msgRGBA.a());
618616
}
619-
void PluginUserMessage::SetRepeatedColor(std::string pszFieldName, int index, const Color &value)
617+
void PluginUserMessage::SetRepeatedColor(std::string pszFieldName, int index, const Color& value)
620618
{
621619
GETCHECK_FIELD();
622620
CHECK_FIELD_TYPE_VOID(MESSAGE);
623621
CHECK_FIELD_REPEATED();
624622
CHECK_REPEATED_ELEMENT_VOID(index);
625623

626-
CMsgRGBA *msgRGBA = (CMsgRGBA *)this->msgBuffer->GetReflection()->MutableRepeatedMessage(this->msgBuffer, field, index);
624+
CMsgRGBA* msgRGBA = (CMsgRGBA*)this->msgBuffer->GetReflection()->MutableRepeatedMessage(this->msgBuffer, field, index);
627625
msgRGBA->set_r(value.r());
628626
msgRGBA->set_g(value.g());
629627
msgRGBA->set_b(value.b());
630628
msgRGBA->set_a(value.a());
631629
}
632-
void PluginUserMessage::AddColor(std::string pszFieldName, const Color &value)
630+
void PluginUserMessage::AddColor(std::string pszFieldName, const Color& value)
633631
{
634632
GETCHECK_FIELD();
635633
CHECK_FIELD_TYPE_VOID(MESSAGE);
636634
CHECK_FIELD_REPEATED();
637635

638-
CMsgRGBA *msgRGBA = (CMsgRGBA *)this->msgBuffer->GetReflection()->AddMessage(this->msgBuffer, field);
636+
CMsgRGBA* msgRGBA = (CMsgRGBA*)this->msgBuffer->GetReflection()->AddMessage(this->msgBuffer, field);
639637
msgRGBA->set_r(value.r());
640638
msgRGBA->set_g(value.g());
641639
msgRGBA->set_b(value.b());
@@ -647,16 +645,16 @@ Vector2D PluginUserMessage::GetVector2D(std::string pszFieldName)
647645
CHECK_FIELD_TYPE(MESSAGE, Vector2D(0, 0));
648646
CHECK_FIELD_NOT_REPEATED(Vector2D(0, 0));
649647

650-
const CMsgVector2D *msgVec2d = (const CMsgVector2D *)&this->msgBuffer->GetReflection()->GetMessage(*this->msgBuffer, field);
648+
const CMsgVector2D* msgVec2d = (const CMsgVector2D*)&this->msgBuffer->GetReflection()->GetMessage(*this->msgBuffer, field);
651649
return Vector2D(msgVec2d->x(), msgVec2d->y());
652650
}
653-
void PluginUserMessage::SetVector2D(std::string pszFieldName, Vector2D &vec)
651+
void PluginUserMessage::SetVector2D(std::string pszFieldName, Vector2D& vec)
654652
{
655653
GETCHECK_FIELD();
656654
CHECK_FIELD_TYPE_VOID(MESSAGE);
657655
CHECK_FIELD_NOT_REPEATED();
658656

659-
CMsgVector2D *msgVec2d = (CMsgVector2D *)this->msgBuffer->GetReflection()->MutableMessage(this->msgBuffer, field);
657+
CMsgVector2D* msgVec2d = (CMsgVector2D*)this->msgBuffer->GetReflection()->MutableMessage(this->msgBuffer, field);
660658
msgVec2d->set_x(vec.x);
661659
msgVec2d->set_y(vec.y);
662660
}
@@ -667,27 +665,27 @@ Vector2D PluginUserMessage::GetRepeatedVector2D(std::string pszFieldName, int in
667665
CHECK_FIELD_REPEATED(Vector2D(0, 0));
668666
CHECK_REPEATED_ELEMENT(index, Vector2D(0, 0));
669667

670-
const CMsgVector2D &msgVec2d = (const CMsgVector2D &)this->msgBuffer->GetReflection()->GetRepeatedMessage(*this->msgBuffer, field, index);
668+
const CMsgVector2D& msgVec2d = (const CMsgVector2D&)this->msgBuffer->GetReflection()->GetRepeatedMessage(*this->msgBuffer, field, index);
671669
return Vector2D(msgVec2d.x(), msgVec2d.y());
672670
}
673-
void PluginUserMessage::SetRepeatedVector2D(std::string pszFieldName, int index, Vector2D &vec)
671+
void PluginUserMessage::SetRepeatedVector2D(std::string pszFieldName, int index, Vector2D& vec)
674672
{
675673
GETCHECK_FIELD();
676674
CHECK_FIELD_TYPE_VOID(MESSAGE);
677675
CHECK_FIELD_REPEATED();
678676
CHECK_REPEATED_ELEMENT_VOID(index);
679677

680-
CMsgVector2D *msgVec2d = (CMsgVector2D *)this->msgBuffer->GetReflection()->MutableRepeatedMessage(this->msgBuffer, field, index);
678+
CMsgVector2D* msgVec2d = (CMsgVector2D*)this->msgBuffer->GetReflection()->MutableRepeatedMessage(this->msgBuffer, field, index);
681679
msgVec2d->set_x(vec.x);
682680
msgVec2d->set_y(vec.y);
683681
}
684-
void PluginUserMessage::AddVector2D(std::string pszFieldName, Vector2D &vec)
682+
void PluginUserMessage::AddVector2D(std::string pszFieldName, Vector2D& vec)
685683
{
686684
GETCHECK_FIELD();
687685
CHECK_FIELD_TYPE_VOID(MESSAGE);
688686
CHECK_FIELD_REPEATED();
689687

690-
CMsgVector2D *msgVec2d = (CMsgVector2D *)this->msgBuffer->GetReflection()->AddMessage(this->msgBuffer, field);
688+
CMsgVector2D* msgVec2d = (CMsgVector2D*)this->msgBuffer->GetReflection()->AddMessage(this->msgBuffer, field);
691689
msgVec2d->set_x(vec.x);
692690
msgVec2d->set_y(vec.y);
693691
}
@@ -697,16 +695,16 @@ Vector PluginUserMessage::GetVector(std::string pszFieldName)
697695
CHECK_FIELD_TYPE(MESSAGE, Vector(0, 0, 0));
698696
CHECK_FIELD_NOT_REPEATED(Vector(0, 0, 0));
699697

700-
const CMsgVector *msgVec = (const CMsgVector *)&this->msgBuffer->GetReflection()->GetMessage(*this->msgBuffer, field);
698+
const CMsgVector* msgVec = (const CMsgVector*)&this->msgBuffer->GetReflection()->GetMessage(*this->msgBuffer, field);
701699
return Vector(msgVec->x(), msgVec->y(), msgVec->z());
702700
}
703-
void PluginUserMessage::SetVector(std::string pszFieldName, Vector &vec)
701+
void PluginUserMessage::SetVector(std::string pszFieldName, Vector& vec)
704702
{
705703
GETCHECK_FIELD();
706704
CHECK_FIELD_TYPE_VOID(MESSAGE);
707705
CHECK_FIELD_NOT_REPEATED();
708706

709-
CMsgVector *msgVec = (CMsgVector *)this->msgBuffer->GetReflection()->MutableMessage(this->msgBuffer, field);
707+
CMsgVector* msgVec = (CMsgVector*)this->msgBuffer->GetReflection()->MutableMessage(this->msgBuffer, field);
710708
msgVec->set_x(vec.x);
711709
msgVec->set_y(vec.y);
712710
msgVec->set_z(vec.z);
@@ -718,28 +716,28 @@ Vector PluginUserMessage::GetRepeatedVector(std::string pszFieldName, int index)
718716
CHECK_FIELD_REPEATED(Vector(0, 0, 0));
719717
CHECK_REPEATED_ELEMENT(index, Vector(0, 0, 0));
720718

721-
const CMsgVector &msgVec = (const CMsgVector &)this->msgBuffer->GetReflection()->GetRepeatedMessage(*this->msgBuffer, field, index);
719+
const CMsgVector& msgVec = (const CMsgVector&)this->msgBuffer->GetReflection()->GetRepeatedMessage(*this->msgBuffer, field, index);
722720
return Vector(msgVec.x(), msgVec.y(), msgVec.z());
723721
}
724-
void PluginUserMessage::SetRepeatedVector(std::string pszFieldName, int index, Vector &vec)
722+
void PluginUserMessage::SetRepeatedVector(std::string pszFieldName, int index, Vector& vec)
725723
{
726724
GETCHECK_FIELD();
727725
CHECK_FIELD_TYPE_VOID(MESSAGE);
728726
CHECK_FIELD_REPEATED();
729727
CHECK_REPEATED_ELEMENT_VOID(index);
730728

731-
CMsgVector *msgVec = (CMsgVector *)this->msgBuffer->GetReflection()->MutableRepeatedMessage(this->msgBuffer, field, index);
729+
CMsgVector* msgVec = (CMsgVector*)this->msgBuffer->GetReflection()->MutableRepeatedMessage(this->msgBuffer, field, index);
732730
msgVec->set_x(vec.x);
733731
msgVec->set_y(vec.y);
734732
msgVec->set_z(vec.z);
735733
}
736-
void PluginUserMessage::AddVector(std::string pszFieldName, Vector &vec)
734+
void PluginUserMessage::AddVector(std::string pszFieldName, Vector& vec)
737735
{
738736
GETCHECK_FIELD();
739737
CHECK_FIELD_TYPE_VOID(MESSAGE);
740738
CHECK_FIELD_REPEATED();
741739

742-
CMsgVector *msgVec = (CMsgVector *)this->msgBuffer->GetReflection()->AddMessage(this->msgBuffer, field);
740+
CMsgVector* msgVec = (CMsgVector*)this->msgBuffer->GetReflection()->AddMessage(this->msgBuffer, field);
743741
msgVec->set_x(vec.x);
744742
msgVec->set_y(vec.y);
745743
msgVec->set_z(vec.z);
@@ -750,16 +748,16 @@ QAngle PluginUserMessage::GetQAngle(std::string pszFieldName)
750748
CHECK_FIELD_TYPE(MESSAGE, QAngle(0, 0, 0));
751749
CHECK_FIELD_NOT_REPEATED(QAngle(0, 0, 0));
752750

753-
const CMsgQAngle *msgAng = (const CMsgQAngle *)&this->msgBuffer->GetReflection()->GetMessage(*this->msgBuffer, field);
751+
const CMsgQAngle* msgAng = (const CMsgQAngle*)&this->msgBuffer->GetReflection()->GetMessage(*this->msgBuffer, field);
754752
return QAngle(msgAng->x(), msgAng->y(), msgAng->z());
755753
}
756-
void PluginUserMessage::SetQAngle(std::string pszFieldName, QAngle &vec)
754+
void PluginUserMessage::SetQAngle(std::string pszFieldName, QAngle& vec)
757755
{
758756
GETCHECK_FIELD();
759757
CHECK_FIELD_TYPE_VOID(MESSAGE);
760758
CHECK_FIELD_NOT_REPEATED();
761759

762-
CMsgQAngle *msgAng = (CMsgQAngle *)this->msgBuffer->GetReflection()->MutableMessage(this->msgBuffer, field);
760+
CMsgQAngle* msgAng = (CMsgQAngle*)this->msgBuffer->GetReflection()->MutableMessage(this->msgBuffer, field);
763761
msgAng->set_x(vec.x);
764762
msgAng->set_y(vec.y);
765763
msgAng->set_z(vec.z);
@@ -771,28 +769,28 @@ QAngle PluginUserMessage::GetRepeatedQAngle(std::string pszFieldName, int index)
771769
CHECK_FIELD_REPEATED(QAngle(0, 0, 0));
772770
CHECK_REPEATED_ELEMENT(index, QAngle(0, 0, 0));
773771

774-
const CMsgQAngle &msgAng = (const CMsgQAngle &)this->msgBuffer->GetReflection()->GetRepeatedMessage(*this->msgBuffer, field, index);
772+
const CMsgQAngle& msgAng = (const CMsgQAngle&)this->msgBuffer->GetReflection()->GetRepeatedMessage(*this->msgBuffer, field, index);
775773
return QAngle(msgAng.x(), msgAng.y(), msgAng.z());
776774
}
777-
void PluginUserMessage::SetRepeatedQAngle(std::string pszFieldName, int index, QAngle &vec)
775+
void PluginUserMessage::SetRepeatedQAngle(std::string pszFieldName, int index, QAngle& vec)
778776
{
779777
GETCHECK_FIELD();
780778
CHECK_FIELD_TYPE_VOID(MESSAGE);
781779
CHECK_FIELD_REPEATED();
782780
CHECK_REPEATED_ELEMENT_VOID(index);
783781

784-
CMsgQAngle *msgAng = (CMsgQAngle *)this->msgBuffer->GetReflection()->MutableRepeatedMessage(this->msgBuffer, field, index);
782+
CMsgQAngle* msgAng = (CMsgQAngle*)this->msgBuffer->GetReflection()->MutableRepeatedMessage(this->msgBuffer, field, index);
785783
msgAng->set_x(vec.x);
786784
msgAng->set_y(vec.y);
787785
msgAng->set_z(vec.z);
788786
}
789-
void PluginUserMessage::AddQAngle(std::string pszFieldName, QAngle &vec)
787+
void PluginUserMessage::AddQAngle(std::string pszFieldName, QAngle& vec)
790788
{
791789
GETCHECK_FIELD();
792790
CHECK_FIELD_TYPE_VOID(MESSAGE);
793791
CHECK_FIELD_REPEATED();
794792

795-
CMsgQAngle *msgAng = (CMsgQAngle *)this->msgBuffer->GetReflection()->AddMessage(this->msgBuffer, field);
793+
CMsgQAngle* msgAng = (CMsgQAngle*)this->msgBuffer->GetReflection()->AddMessage(this->msgBuffer, field);
796794
msgAng->set_x(vec.x);
797795
msgAng->set_y(vec.y);
798796
msgAng->set_z(vec.z);
@@ -803,15 +801,15 @@ void PluginUserMessage::RemoveRepeatedFieldValue(std::string pszFieldName, int i
803801
CHECK_FIELD_REPEATED();
804802
CHECK_REPEATED_ELEMENT_VOID(index);
805803

806-
const google::protobuf::Reflection *pReflection = this->msgBuffer->GetReflection();
804+
const google::protobuf::Reflection* pReflection = this->msgBuffer->GetReflection();
807805
for (int i = index; i < elemCount - 1; ++i)
808806
pReflection->SwapElements(this->msgBuffer, field, i, i + 1);
809807

810808
pReflection->RemoveLast(this->msgBuffer, field);
811809
}
812810
int PluginUserMessage::GetRepeatedFieldCount(std::string pszFieldName)
813811
{
814-
const google::protobuf::FieldDescriptor *field = this->msgBuffer->GetDescriptor()->FindFieldByName(pszFieldName.c_str());
812+
const google::protobuf::FieldDescriptor* field = this->msgBuffer->GetDescriptor()->FindFieldByName(pszFieldName.c_str());
815813
if (!field)
816814
return -1;
817815

@@ -840,7 +838,7 @@ void PluginUserMessage::SendToAllPlayers()
840838
if (!this->msgBuffer)
841839
return;
842840

843-
CBroadcastRecipientFilter *filter = new CBroadcastRecipientFilter;
841+
CBroadcastRecipientFilter* filter = new CBroadcastRecipientFilter;
844842
g_pGameEventSystem->PostEventAbstract(0, false, filter, this->internalMsg, this->msgBuffer, 0);
845843
delete filter;
846844
}

0 commit comments

Comments
 (0)