• Welcome to Valhalla Legends Archive.
 

MBNCSUtil.CheckRevision.ExtractMPQNumber

Started by Chriso, September 19, 2007, 08:34 AM

Previous topic - Next topic

Chriso

I keep receiving a run-time error "Input string was not in a correct format." for this line of code:

            int MpqNum = CheckRevision.ExtractMPQNumber(MpqName);

Any ideas why I am getting this error?

rabbit

Maybe if you posted some input strings...
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

Chriso

      MpqName   "lockdown-IX86-18.mpq"   string
      MpqNum   0   int

Those are the inputs...

MyndFyre

As MBNCSUtil doesn't yet support lockdown, it also doesn't support extracting lockdown MPQ numbers.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Camel

If you need it, your best bet would be to completely circumvent that library and use BNLS_VERSIONCHECKEX2.

Barabajagal


Camel

Or, this Java library:

   try {
                      InetAddress address = MirrorSelector.getClosestMirror(cs.bnlsServer, cs.bnlsPort);
                      Socket conn = new Socket(address, cs.bnlsPort);

                      recieveInfo("Connected to " + address + ":" + cs.bnlsPort);

                      BNLSPacket bnlsOut = new BNLSPacket(BNLSCommandIDs.BNLS_VERSIONCHECKEX2);
                      bnlsOut.writeDWord(cs.product);
                      bnlsOut.writeDWord(0);   // Flags
                      bnlsOut.writeDWord(0);   // Cookie
                      bnlsOut.writeQWord(MPQFileTime);
                      bnlsOut.writeNTString(MPQFileName);
                      bnlsOut.writeNTString(ValueStr);
                      bnlsOut.SendPacket(conn.getOutputStream(), cs.packetLog);

                      InputStream bnlsInputStream = conn.getInputStream();
                      long startTime = System.currentTimeMillis();
                      while(bnlsInputStream.available() < 3) {
                         Thread.sleep(10);
                         Thread.yield();

                         long timeElapsed = System.currentTimeMillis() - startTime;
                         if(timeElapsed > 5000)
                            throw new Exception("BNLS_VERSIONCHECKEX2 timeout");
                      }

                      BNLSPacketReader bpr = new BNLSPacketReader(bnlsInputStream, cs.packetLog);
                      BNetInputStream bnlsIn = bpr.getInputStream();
                      int success = bnlsIn.readDWord();
                      if(success != 1) {
                         Out.error(getClass(), "BNLS_VERSIONCHECKEX2 Failed\n" + HexDump.hexDump(bpr.getData()));
                         throw new Exception("BNLS failed to complete BNLS_VERSIONCHECKEX2 sucessfully");
                      }
                      exeVersion = bnlsIn.readDWord();
                      exeHash = bnlsIn.readDWord();
                      exeInfo = bnlsIn.readNTString();
                      bnlsIn.readDWord(); // cookie
                      /*int exeVerbyte =*/ bnlsIn.readDWord();
                      assert(bnlsIn.available() == 0);

                      recieveInfo("Recieved CheckRevision from BNLS");

                      conn.close();
                   } catch(UnknownHostException e) {
                      recieveError("BNLS connection failed: " + e.getMessage());
                      setConnected(false);
                      break;
                   }

                   if((exeVersion == 0) || (exeHash == 0) || (exeInfo == null) || (exeInfo.length() == 0)) {
                      recieveError("Checkrevision failed!");
                      setConnected(false);
                      break;
                   }


See:
http://bnubot.googlecode.com/svn/trunk/BNUBot/src/net/bnubot/core/bncs/BNCSConnection.java
http://bnubot.googlecode.com/svn/trunk/BNUBot/src/net/bnubot/core/bnls/

devcode

A nice huge project there Camel ;) SVN unfortunately sucks, Perforce > *

Quote from: Camel on September 20, 2007, 11:34 PM
Or, this Java library:

   try {
                      InetAddress address = MirrorSelector.getClosestMirror(cs.bnlsServer, cs.bnlsPort);
                      Socket conn = new Socket(address, cs.bnlsPort);

                      recieveInfo("Connected to " + address + ":" + cs.bnlsPort);

                      BNLSPacket bnlsOut = new BNLSPacket(BNLSCommandIDs.BNLS_VERSIONCHECKEX2);
                      bnlsOut.writeDWord(cs.product);
                      bnlsOut.writeDWord(0);   // Flags
                      bnlsOut.writeDWord(0);   // Cookie
                      bnlsOut.writeQWord(MPQFileTime);
                      bnlsOut.writeNTString(MPQFileName);
                      bnlsOut.writeNTString(ValueStr);
                      bnlsOut.SendPacket(conn.getOutputStream(), cs.packetLog);

                      InputStream bnlsInputStream = conn.getInputStream();
                      long startTime = System.currentTimeMillis();
                      while(bnlsInputStream.available() < 3) {
                         Thread.sleep(10);
                         Thread.yield();

                         long timeElapsed = System.currentTimeMillis() - startTime;
                         if(timeElapsed > 5000)
                            throw new Exception("BNLS_VERSIONCHECKEX2 timeout");
                      }

                      BNLSPacketReader bpr = new BNLSPacketReader(bnlsInputStream, cs.packetLog);
                      BNetInputStream bnlsIn = bpr.getInputStream();
                      int success = bnlsIn.readDWord();
                      if(success != 1) {
                         Out.error(getClass(), "BNLS_VERSIONCHECKEX2 Failed\n" + HexDump.hexDump(bpr.getData()));
                         throw new Exception("BNLS failed to complete BNLS_VERSIONCHECKEX2 sucessfully");
                      }
                      exeVersion = bnlsIn.readDWord();
                      exeHash = bnlsIn.readDWord();
                      exeInfo = bnlsIn.readNTString();
                      bnlsIn.readDWord(); // cookie
                      /*int exeVerbyte =*/ bnlsIn.readDWord();
                      assert(bnlsIn.available() == 0);

                      recieveInfo("Recieved CheckRevision from BNLS");

                      conn.close();
                   } catch(UnknownHostException e) {
                      recieveError("BNLS connection failed: " + e.getMessage());
                      setConnected(false);
                      break;
                   }

                   if((exeVersion == 0) || (exeHash == 0) || (exeInfo == null) || (exeInfo.length() == 0)) {
                      recieveError("Checkrevision failed!");
                      setConnected(false);
                      break;
                   }


See:
http://bnubot.googlecode.com/svn/trunk/BNUBot/src/net/bnubot/core/bncs/BNCSConnection.java
http://bnubot.googlecode.com/svn/trunk/BNUBot/src/net/bnubot/core/bnls/

Camel

From what I've read, SVN has the largest stability e-penis, and that's all I care about. Besides, I don't choose what mechanism Google Code uses.

Smarter

How bout you just do:

Convert.ToInt32(mpqFilename.Substring(14, 2));
  - I also added the Convert, so it's ready for your packet:

Example:

ublic void BNLS_VERSIONCHECK()
        {
            DataBuffer s0x09 = new DataBuffer();
            s0x09.InsertInt16(0);
            s0x09.InsertByte((byte)BNLSPacketId.BNLS_VERSIONCHECK);
            s0x09.InsertInt32(0x04);
            s0x09.InsertInt32(Convert.ToInt32(mpqFilename.Substring(14, 2)));
            s0x09.InsertCString(checksumFormula);
            byte[] temp = s0x09.GetData();
            temp[0] = Convert.ToByte(Convert.ToInt16(s0x09.Count));
            bnls.SendData(temp);
            AddChat("BNLS VersionCheck Sent", Color.Black);
        }
Since '99

BrutalNet.Net

Camel

How bout you just do: BNLS_VERSIONCHECKEX2

Chriso

#11
Quote from: Smarter on September 26, 2007, 08:14 AM
How bout you just do:

Convert.ToInt32(mpqFilename.Substring(14, 2));

Because it is not always at position 14 of the string, e.g. IX86-ver-00.mpq (starts at 10), lockdown-IX86-00.mpq (starts at 15), and ver-IX86-00.mpq (starts at 10 as well).

The CheckRevision.extractMPQNumber determines which mpq file it is before extracting the number of the mpq.