The online racing simulator
Private Message command
(3 posts, started )
#1 - MAAD.
Private Message command
Hi, I'm using Visual Studio 2013 Professional Edition. I'm coding 2 private message-commands:

1: !pmuser <username>
2: !pm <message content>

Here's what I have so far:


[Command("pmuser", "pmuser <username>")]
public void pmuser(string Msg, string[] StrMsg, Packets.IS_MSO MSO)
{
{
if (Connections[GetConnIdx(MSO.UCID)].Username == StrMsg[1])
{
InSim.Send_MTC_MessageToConnection("^1*^6 You can't PM yourself", MSO.UCID, 0);
}
else
{
var Conn = Connections[GetConnIdx(MSO.UCID)];
{
Conn.UserFound = false;
foreach (clsConnection C in Connections)
{
if (StrMsg[1] == C.Username)
{
{
Conn.UserFound = true;
C.ReplyToUser = C.Username;
MsgPly("^1*^6 Selected user: ^7" + C.PlayerName, Conn.UniqueID);
}
}
}
if (Conn.UserFound == false)
{
MsgPly("^1*^6 User not found", Conn.UniqueID);
}
}
}
}
}


[Command("pm", "pm <username> <message>")]
public void pm(string Msg, string[] StrMsg, Packets.IS_MSO MSO)
{
if (Connections[GetConnIdx(MSO.UCID)].UserFound == true)
{
var Conn = Connections[GetConnIdx(MSO.UCID)];
{
string Message = Msg.Remove(0, +4);

{
if (Conn.UserFound == true)
{
foreach (clsConnection C in Connections)
{
MsgPly("^1*^3 PM Sent To: ^7" + C.PlayerName, Conn.UniqueID);
MsgPly("^1*^3 Msg: ^7" + Message, Conn.UniqueID);

PMBox("> PM From: " + Conn.NoColPlyName + " (" + Conn.Username + ") to " + C.NoColPlyName + " (" + C.Username + ")");
PMBox("> Msg: " + Message);

MsgPly("^1*^3 PM From: ^7" + Conn.PlayerName + " (" + Conn.Username + ")", C.UniqueID);
MsgPly("^1*^3 Msg: ^7" + Message, C.UniqueID);


if (C.IsSpy == 0)
{
foreach (clsConnection F in Connections)
{
if ((F.IsAdmin == 1 && F.IsSuperAdmin == 1) && F.UniqueID != MSO.UCID)
{
InSim.Send_MTC_MessageToConnection("^1****** ^3SPY ^1******", F.UniqueID, 0);
InSim.Send_MTC_MessageToConnection("^3PM From: ^6" + Conn.NoColPlyName + " ^3to ^6" + C.NoColPlyName, F.UniqueID, 0);
InSim.Send_MTC_MessageToConnection("^3Msg: ^6" + Message, F.UniqueID, 0);
}
}
}
else if (C.IsSpy == 1)
{
foreach (clsConnection F in Connections)
{
if ((F.IsAdmin == 1 && F.IsSuperAdmin == 1) && F.UniqueID != MSO.UCID)
{
InSim.Send_MTC_MessageToConnection("^1PM Spy: ^6PM added to log", F.UniqueID, 0);
}
}
}
}
}
}
}
}
}

The thing is:

- When I execute !pmuser <username>, it works just fine.
- Then I head over to !pm to set some contents, and it sends the message to all connections, even host

Does anyone know how to solve this?
Using C#, LFS External.
foreach applies functions to all users, you have to write some control mechanism.

[Command("pm", "pm <username> <message>")]
public void pm(string Msg, string[] StrMsg, Packets.IS_MSO MSO)
{
if (Connections[GetConnIdx(MSO.UCID)].UserFound == true)
{
var Conn = Connections[GetConnIdx(MSO.UCID)];
{
string Message = Msg.Remove(0, +4);

{
if (Conn.UserFound == true)
{
foreach (clsConnection C in Connections)
{
if (C.Username == C.ReplyToUser)
{
MsgPly("^1*^3 PM Sent To: ^7" + C.PlayerName, Conn.UniqueID);
MsgPly("^1*^3 Msg: ^7" + Message, Conn.UniqueID);

PMBox("> PM From: " + Conn.NoColPlyName + " (" + Conn.Username + ") to " + C.NoColPlyName + " (" + C.Username + ")");
PMBox("> Msg: " + Message);

MsgPly("^1*^3 PM From: ^7" + Conn.PlayerName + " (" + Conn.Username + ")", C.UniqueID);
MsgPly("^1*^3 Msg: ^7" + Message, C.UniqueID);
}
if (C.IsSpy == 0)
{
foreach (clsConnection F in Connections)
{
if ((F.IsAdmin == 1 && F.IsSuperAdmin == 1) && F.UniqueID != MSO.UCID)
{
InSim.Send_MTC_MessageToConnection("^1****** ^3SPY ^1******", F.UniqueID, 0);
InSim.Send_MTC_MessageToConnection("^3PM From: ^6" + Conn.NoColPlyName + " ^3to ^6" + C.NoColPlyName, F.UniqueID, 0);
InSim.Send_MTC_MessageToConnection("^3Msg: ^6" + Message, F.UniqueID, 0);
}
}
}
else if (C.IsSpy == 1)
{
foreach (clsConnection F in Connections)
{
if ((F.IsAdmin == 1 && F.IsSuperAdmin == 1) && F.UniqueID != MSO.UCID)
{
InSim.Send_MTC_MessageToConnection("^1PM Spy: ^6PM added to log", F.UniqueID, 0);
}
}
}
}
}
}
}
}

I think this should work.
#3 - MAAD.
Got better, but now the PM is sent to Host and the chosen player.
Pic: http://prntscr.com/68hjbu

EDIT: The Host thing only appears for the sender, here's what happens for the receiver.

Private Message command
(3 posts, started )
FGED GREDG RDFGDR GSFDG