Example #1
0
        private void con_redeem(ref TmpEntry entry, EndianIO readerIO, EndianIO writerIO, EndianWriter structIO)
        {
            // Grabbing the token from the request.
            string recCpuKey  = Misc.BytesToHexString(readerIO.Reader.ReadBytes(0x10)); // Cross check the CPUKey here with the one in the DB.
            string recSession = Misc.BytesToHexString(readerIO.Reader.ReadBytes(0x10)); // Receiving their sent session to cross check.

            entry.inToken = Misc.BytesToHexString(readerIO.Reader.ReadBytes(0x19));     // We'll need to change the length later.
            if (ConsoleMySQL.getConsole(ref entry))
            {
                if (entry.ClientEnabled)
                {
                    if (ConsoleMySQL.getToken(ref entry))
                    {
                        entry.daysLeft = !entry.TokenUsed ? entry.daysLeft + entry.TokenDays : entry.daysLeft;
                        string retMsgSuccess = String.Format("Token has been successfully redeemed!\nCPUKey: {0}\nRedeemed {1} Days\n{2}\0", entry.CPUKey, entry.TokenDays, (entry.daysLeft >= 500 ? "You still have lifetime." : "You have " + entry.daysLeft + " days on reserve.")),
                               retMsgUsed    = String.Format("Token seems to already be used.\n\nIf you feel this is a mistake, please message staff ASAP!\n\nYour CPUKey: {0}\0", entry.CPUKey);
                        uint   size          = (sizeof(uint) * 4) + Convert.ToUInt32((!entry.TokenUsed ? retMsgSuccess.Length : retMsgUsed.Length) + 2);
                        byte[] tmpBuff       = new byte[size];
                        mainBuff = new byte[size];
                        Buffer.BlockCopy(Encoding.ASCII.GetBytes(retMsgSuccess), 0, tmpBuff, 0, (!entry.TokenUsed ? retMsgSuccess.Length : retMsgUsed.Length) + 2);
                        structIO.Write(Globals.XSTL_STATUS_SUCCESS);
                        structIO.Write(!entry.TokenUsed ? retMsgSuccess : retMsgUsed);
                        writerIO.Writer.Write(mainBuff);
                        Globals.write("Client [{0}] CPUKey: {1}\n{2} Token: {3}", IPAddr, entry.CPUKey, (!entry.TokenUsed ? "Redeemed" : "Tried Redeeming"), entry.outToken);
                        if (!entry.TokenUsed)
                        {
                            ConsoleMySQL.saveToken(ref entry); ConsoleMySQL.saveConsole(ref entry);
                        }
                        return;
                    }
                    structIO.Write(Globals.XSTL_STATUS_ERROR);
                }
            }
        }