This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently

100 views
Skip to first unread message

Midgard Nuñez Gurillo

unread,
Jun 27, 2015, 4:40:55 PM6/27/15
to lidgren-ne...@googlegroups.com
Hi there, so I'm working on a really simple multiplayer game where the server generates a grid of hexagons, then the players can join in and take these hexagons (so they control some space on that grid where other players want a piece of the cake!), but I'm having an annoying problem while sending the message where players request that they're taking a desired hexagon (by id).

The exception, as the title says is: This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently

I'm using NetPeer.SendToAll for this, this is my code at the moment:

case (byte)Client.ON_REQUEST_TAKE:
                                int takenHexagonId = incoming.ReadInt32();

                                Hexagon taken = hexagons.Find(h => h.id == takenHexagonId);
                                NetPlayer newOwner = players.Find(p => p.connection == incoming.SenderConnection);

                                if (newOwner != null && taken != null)
                                {
                                    taken.playerOwnerID = newOwner.id;

                                    // Broadcast to everyone
                                        outgoing = server.CreateMessage();
                                        outgoing.Write((byte)Server.ON_HEXAGON_TAKEN);
                                        outgoing.Write((int)taken.id);
                                        outgoing.Write((int)taken.playerOwnerID);
                                        server.SendToAll(outgoing, NetDeliveryMethod.ReliableOrdered);
                                }
                                break;

What's happening?

And also if you can help me on another little thing, when the server kicks someone it sends a string with the disconnect message using NetPeer.Disconnect("whatever");, but on the player's end
the string isn't received completely, if for an example the message sent is "Disconnected because you're cheating" in the player's end it would appear "Disc".

The game is being developed in Unity 5.1, but I've been having this small problem since 4.x, I don't really know if it's a Unity problem or what, haven't tested using console clients or whatever.

Thanks in advance!

Midgard

unread,
Jun 27, 2015, 5:02:32 PM6/27/15
to lidgren-ne...@googlegroups.com
Hmmm I researched a bit and it appears to be fixed now.

It definitelly was a problem from Unity, how did I fix it? I simply changed the method where I was reading incoming messages, from Update() to OnGUI(), all thanks to a thread on here that recommends to use OnGUI()!

But I still have the small problem of disconnect messages not arriving or reading completely :(

--
You received this message because you are subscribed to the Google Groups "lidgren-network-gen3" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lidgren-network-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages