Esempio n. 1
0
        public virtual void HandleMcpeLogin(McpeLogin message)
        {
            //Disconnect("Este servidor ya no existe. Por favor, conecta a " + ChatColors.Aqua + "play.bladestorm.net" + ChatColors.White + " para seguir jugando.");
            ////Disconnect("This server is closed. Please connect to " + ChatColors.Aqua + "play.bladestorm.net" + ChatColors.White + " to continue playing.");
            //return;

            // Only one login!
            lock (_loginSyncLock)
            {
                if (_session.Username != null)
                {
                    Log.Info($"Player {_session.Username} doing multiple logins");
                    return;                     // Already doing login
                }

                _session.Username = string.Empty;
            }

            if (message.protocolVersion < 81)
            {
                _session.Disconnect($"Wrong version ({message.protocolVersion}) of Minecraft Pocket Edition, please upgrade.");
                return;
            }

            // THIS counter exist to protect the level from being swamped with player list add
            // attempts during startup (normally).

            DecodeCert(message);

            //if (!message.username.Equals("gurun") && !message.username.Equals("TruDan") && !message.username.Equals("Morehs"))
            //{
            //	if (serverInfo.NumberOfPlayers > serverInfo.MaxNumberOfPlayers)
            //	{
            //		Disconnect("Too many players (" + serverInfo.NumberOfPlayers + ") at this time, please try again.");
            //		return;
            //	}

            //	// Use for loadbalance only right now.
            //	if (serverInfo.ConnectionsInConnectPhase > serverInfo.MaxNumberOfConcurrentConnects)
            //	{
            //		Disconnect("Too many concurrent logins (" + serverInfo.ConnectionsInConnectPhase + "), please try again.");
            //		return;
            //	}
            //}

            //if (message.username == null || message.username.Trim().Length == 0 || !Regex.IsMatch(message.username, "^[A-Za-z0-9_-]{3,56}$"))
            //{
            //	Disconnect("Invalid username.");
            //	return;
            //}

            ////string fileName = Path.GetTempPath() + "Skin_" + Skin.SkinType + ".png";
            ////Log.Info($"Writing skin to filename: {fileName}");
            ////Skin.SaveTextureToFile(fileName, Skin.Texture);
        }
Esempio n. 2
0
        private void HandleSplitMessage(PlayerNetworkSession playerSession, SplitPartPackage splitMessage)
        {
            int spId    = splitMessage.SplitId;
            int spIdx   = splitMessage.SplitIdx;
            int spCount = splitMessage.SplitCount;

            Int24       sequenceNumber        = splitMessage.DatagramSequenceNumber;
            Reliability reliability           = splitMessage.Reliability;
            Int24       reliableMessageNumber = splitMessage.ReliableMessageNumber;
            Int24       orderingIndex         = splitMessage.OrderingIndex;
            byte        orderingChannel       = splitMessage.OrderingChannel;

            SplitPartPackage[] spPackets;
            bool haveEmpty = false;

            // Need sync for this part since they come very fast, and very close in time.
            // If no synk, will often detect complete message two times (or more).
            lock (playerSession.Splits)
            {
                if (!playerSession.Splits.ContainsKey(spId))
                {
                    playerSession.Splits.TryAdd(spId, new SplitPartPackage[spCount]);
                }

                spPackets = playerSession.Splits[spId];
                if (spPackets[spIdx] != null)
                {
                    Log.Debug("Already had splitpart (resent). Ignore this part.");
                    return;
                }
                spPackets[spIdx] = splitMessage;

                for (int i = 0; i < spPackets.Length; i++)
                {
                    haveEmpty = haveEmpty || spPackets[i] == null;
                }
            }

            if (!haveEmpty)
            {
                Log.DebugFormat("Got all {0} split packages for split ID: {1}", spCount, spId);

                SplitPartPackage[] waste;
                playerSession.Splits.TryRemove(spId, out waste);

                using (MemoryStream stream = MemoryStreamManager.GetStream())
                {
                    for (int i = 0; i < spPackets.Length; i++)
                    {
                        SplitPartPackage splitPartPackage = spPackets[i];
                        byte[]           buf = splitPartPackage.Message;
                        if (buf == null)
                        {
                            Log.Error("Expected bytes in splitpart, but got none");
                            continue;
                        }

                        stream.Write(buf, 0, buf.Length);
                        splitPartPackage.PutPool();
                    }

                    byte[] buffer = stream.ToArray();
                    try
                    {
                        ConnectedPackage newPackage = ConnectedPackage.CreateObject();
                        newPackage._datagramSequenceNumber = sequenceNumber;
                        newPackage._reliability            = reliability;
                        newPackage._reliableMessageNumber  = reliableMessageNumber;
                        newPackage._orderingIndex          = orderingIndex;
                        newPackage._orderingChannel        = (byte)orderingChannel;
                        newPackage._hasSplit = false;

                        Package fullMessage = PackageFactory.CreatePackage(buffer[0], buffer, "raknet") ??
                                              new UnknownPackage(buffer[0], buffer);
                        fullMessage.DatagramSequenceNumber = sequenceNumber;
                        fullMessage.Reliability            = reliability;
                        fullMessage.ReliableMessageNumber  = reliableMessageNumber;
                        fullMessage.OrderingIndex          = orderingIndex;
                        fullMessage.OrderingChannel        = orderingChannel;

                        newPackage.Messages = new List <Package>();
                        newPackage.Messages.Add(fullMessage);

                        Log.Debug(
                            $"Assembled split package {newPackage._reliability} message #{newPackage._reliableMessageNumber}, Chan: #{newPackage._orderingChannel}, OrdIdx: #{newPackage._orderingIndex}");
                        HandleConnectedPackage(playerSession, newPackage);
                        newPackage.PutPool();
                    }
                    catch (Exception e)
                    {
                        Log.Error("Error during split message parsing", e);
                        if (Log.IsDebugEnabled)
                        {
                            Log.Debug($"0x{buffer[0]:x2}\n{Package.HexDump(buffer)}");
                        }
                        playerSession.Disconnect("Bad package received from client.", false);
                    }
                }
            }
        }