Ejemplo n.º 1
0
        public static void SendViaProto(global::ProtoMessage.ProtoMessage m, NetConnection conn, bool isPCL, NetEncryption alg = null)
        {
            Contract.Requires(m != null && conn != null);
            NetOutgoingMessage msg = server.CreateMessage();
            MemoryStream       ms  = new MemoryStream();

            Serializer.SerializeWithLengthPrefix <global::ProtoMessage.ProtoMessage>(ms, m, PrefixStyle.Fixed32);
            msg.Write(ms.GetBuffer());
            if (alg != null)
            {
                msg.Encrypt(alg);
            }
            server.SendMessage(msg, conn, NetDeliveryMethod.ReliableOrdered);
            server.FlushSendQueue();
        }
Ejemplo n.º 2
0
        public void ProcessMessage(global::ProtoMessage.ProtoMessage m, NetConnection connection)
        {
            Contract.Requires(connection != null && m != null);
            Client client;

            clientConnections.TryGetValue(connection, out client);
            if (client == null)
            {
                NetOutgoingMessage errorMessage =
                    server.CreateMessage("There was a problem with the connection. Please try re-connecting");
                server.SendMessage(errorMessage, connection, NetDeliveryMethod.ReliableOrdered);
                string log = "Connection from peer " + connection.Peer.UniqueIdentifier +
                             " not found in client connections. Timestamp: " +
                             DateTime.Now.ToString(DateTimeFormatInfo.CurrentInfo);
                Globals_Server.logError(log);
                return;
            }
            var pc = client.myPlayerCharacter;

            if (pc == null || !pc.isAlive)
            {
                NetOutgoingMessage msg = server.CreateMessage("You have no valid PlayerCharacter!");
                server.SendMessage(msg, connection, NetDeliveryMethod.ReliableOrdered);
                server.FlushSendQueue();
            }
            else
            {
                ProtoMessage forActionController = new ProtoMessage();
                string       responseType        = m.ResponseType.ToString();

                /*forActionController.ResponseType = responseType;
                 * ProtoMessage reply = Game.ActionController(m, client);
                 * // Set action type to ensure client knows which action invoked response
                 * if (reply == null)
                 * {
                 *  ProtoMessage invalid = new ProtoMessage(DisplayMessages.ErrorGenericMessageInvalid);
                 *  invalid.ActionType = Actions.Update;
                 *  reply = invalid;
                 * }
                 * else
                 * {
                 *  reply.ActionType = m.ActionType;
                 * }
                 * SendViaProto(reply, connection, true, client.alg);
                 * Globals_Server.logEvent("From " + clientConnections[connection] + ": request = " +
                 *                      m.ActionType.ToString() + ", reply = " + reply.ResponseType.ToString());*/
            }
        }