Example #1
0
        private void loginHandler(object sender, ServerLoginEventArgs args)
        {
            lock (messageHistoryLock)
            {
                // Create a chat history packet
                ChatHistoryPacket packet = new ChatHistoryPacket();

                // Convert each chat message to their packet counterparts
                foreach (ChatMessage chatMessage in messageHistory)
                {
                    // Create a chat message packet and add it to the history packet
                    packet.ChatMessages.Add(
                        new ChatMessagePacket
                    {
                        Uuid      = chatMessage.SenderUuid,
                        MessageId = chatMessage.MessageId,
                        Message   = chatMessage.Message,
                        Timestamp = chatMessage.Timestamp.ToTimestamp()
                    }
                        );
                }

                // Pack the history packet
                Any packedPacket = ProtobufPacketHelper.Pack(packet);

                // Send it on its way
                if (!netServer.TrySend(args.ConnectionId, MODULE_NAME, packedPacket.ToByteArray()))
                {
                    RaiseLogEntry(new LogEventArgs("Failed to send ChatHistoryPacket to connection " + args.ConnectionId.Highlight(HighlightType.ConnectionID), LogLevel.ERROR));
                }
            }
        }
Example #2
0
        private void loginEventHandler(object sender, ServerLoginEventArgs args)
        {
            // Send the user a list of their active trades
            lock (tradeDataLock)
            {
                // Get all trades involving the user
                List <Trade> trades = activeTrades.Values.Where(trade => trade.PartyUuids.Contains(args.Uuid)).ToList();

                // Make sure there are trades to send before sending any
                if (trades.Count != 0)
                {
                    // Send the user a sync packet with each trade
                    sendSyncTradesPacket(args.ConnectionId, trades, args.Uuid);
                }

                // Notify the user of trades they were not notified of earlier
                // Get all trades where the user is pending notification
                IEnumerable <CompletedTrade> tradesPendingNotification = completedTrades.Values.Where(trade => trade.PendingNotification.Contains(args.Uuid));

                List <string> tradesToRemove = new List <string>();
                foreach (CompletedTrade completedTrade in tradesPendingNotification)
                {
                    Trade trade = completedTrade.Trade;

                    // Try get the other party's UUID, continuing on failure
                    if (!trade.TryGetOtherParty(args.Uuid, out string otherPartyUuid))
                    {
                        continue;
                    }

                    if (completedTrade.Cancelled)
                    {
                        // Try get the user's items, continuing on failure
                        if (!trade.TryGetItemsOnOffer(args.Uuid, out ProtoThing[] things))