1 # ======================================================================
4 # Copyright 2003 Sony Online Entertainment, Inc.
7 # ======================================================================
9 # Used to output customization data assignments for objects in a
10 # SWG database. Can view customization values for a list of object
11 # ids or for all object ids in the database.
13 # Perl modules DBI and DBD::Oracle must be installed to run this tool. See www.perl.com for info on getting these modules.
14 # You must have PERL5LIB (or PERLLIB) set to your mapping for //depot/swg/current/tools/perllib.
21 # ======================================================================
23 # ======================================================================
29 my $password = "changeme";
30 my $databaseName = "swodb";
36 my $useFormatVersion = 1;
38 my $defaultFilename = '../dsrc/sku.0/sys.shared/compiled/game/customization/customization_id_manager.mif';
39 my $customizationIdManagerFilename = $defaultFilename;
44 my $dumpFileEntryNumber = 1;
46 # ======================================================================
50 print "Calling syntax:\n";
55 print "view human-readable customization from database:\n";
56 print "\t$0 -V -u <database username> [-p <database password>] [-D <database>] [-d]\n";
57 print "\t [-m <pathToCustomizationIdManagerMifFile>] [-f format]\n";
58 print "\t [-a | [objectId [objectId...]]]\n";
60 print "change customization data in the database:\n";
61 print "\t$0 -C -u <database username> [-p <database password>] [-D <database>] [-d]\n";
62 print "\t -1 <path to 1-line format dump file> [-e <entry number within dump file>] objectId\n";
64 print "Option description:\n";
65 print "\t-V: major operating mode: view database info.\n";
66 print "\t-C: major operating mode: change database entry.\n";
67 print "\t-u: specifies the name of the user for the Oracle database.\n";
68 print "\t-p: [optional] specifies the password for the user of the Oracle database. Default: changeme.\n";
69 print "\t-D: [optional] specifies the database to attach to. Default: swodb.\n";
70 print "\t-d: [optional] turn on extensive debug-level output.\n";
71 print "\t-m: [optional] specify path to CustomizationIdManager's mif version of initialization file.\n";
72 print "\t Default: $defaultFilename\n";
73 print "\t-a: [optional] list customization variables for all objects in the database that have any customization info.\n";
74 print "\t-f: [optional] customization string format: format = 1 (for new packed format version 1), old2 (for old unpacked format version 2).\n";
75 print "\t Default: 1.\n";
76 print "\t-h: [optional] print this help info.\n";
77 print "\t-1: filename containing 1-line dump format (one entry per line) of Oracle select dump(appearance_data) data.\n";
78 print "\t-e: [optional] specifies the 1-based entry count to use if the dump file has multiple lines. Default: 1.\n";
81 # ======================================================================
88 while (defined($ARGV[0]) && ($ARGV[0] =~ m/^-(.*)$/))
95 print "-u option missing <database username> specification.\n";
100 $userName = $ARGV[1];
101 print "<username: $userName>\n" if $debug;
111 print "-p option missing <password> specification.\n";
116 $password = $ARGV[1];
117 print "<password: $password>\n" if $debug;
124 # Grab database name.
127 print "-D option missing <database> specification.\n";
132 $databaseName = $ARGV[1];
133 print "<database: $databaseName>\n" if $debug;
141 print "major mode is change\n" if $debug;
146 $Customization::Debug
= 1;
161 print "-m option missing <CustomizationIdManager MIF file> specification.\n";
166 $customizationIdManagerFilename = $ARGV[1];
167 print "<customizationIdManagerFilename: $customizationIdManagerFilename\n" if $debug;
177 print "-f option missing <format> specification.\n";
182 if ($ARGV[1] =~ s/^old//i)
186 print "<useOldFormat: $useOldFormat>\n" if $debug;
188 $useFormatVersion = $ARGV[1];
189 print "<useFormatVersion: $useFormatVersion>\n" if $debug;
197 print "major mode is viewing\n" if $debug;
201 $dumpFileName = $ARGV[1];
204 print "dumpFileName=[$dumpFileName]\n" if $debug;
208 $dumpFileEntryNumber = $ARGV[1];
210 print "dumpFileEntryNumber=$dumpFileEntryNumber\n" if $debug;
214 warn "unknown option [$1].";
218 # Process next argument.
222 # Check for missing options.
223 if (!$showHelp && (length $userName < 1))
225 print "missing -u username option.\n";
229 # Make sure show all or command line args exist.
230 if (!$showHelp && (!$showAll && (@ARGV < 1)))
232 print "must specify one or more object IDs or -a option for all objects.\n";
236 # Show help as needed.
237 if ($showHelp || ($exitCode != 0))
244 sub getVariableInfo
(\
%$)
246 my $variableInfoRef = shift;
247 my $customizationString = shift;
251 if ($useFormatVersion == 2)
253 getVariableInfoFromOldString
(%$variableInfoRef, $customizationString);
257 die "The only old version format supported is version 2, user specified [$useFormatVersion].";
262 if ($useFormatVersion == 1)
264 getVariableInfoFromNewString
(%$variableInfoRef, $customizationString);
268 die "New version format [$useFormatVersion] unsupported.";
273 # ======================================================================
277 my $objectId = shift;
278 my $variableInfoRef = shift;
280 print "object id: $objectId\n";
281 dumpVariableInfo
(%$variableInfoRef);
286 # ======================================================================
292 # Validate row entry count.
293 die "Returned row has " . @
$rowRef . "entries, expecting 2." if (@
$rowRef != 2);
295 # Retrieve object id and old customization data.
296 my $objectId = $$rowRef[0];
297 my $customizationString = $$rowRef[1];
298 print "<row: id=[$objectId]: string length [" . (length $customizationString) . "]>\n" if $debug;
300 my %variableInfo = ();
302 my $success = getVariableInfo
(%variableInfo, $customizationString);
303 die "getVariableInfo() failed for object id [$objectId]." if !$success;
305 printView
($objectId, %variableInfo);
308 # ======================================================================
314 print "<viewing: all>\n" if $debug;
316 # Prepare the SELECT statement: grab all non-empty appearance_data and associated object ids.
317 my $statementHandle = $dbHandle->prepare("SELECT object_id, appearance_data FROM tangible_objects WHERE LENGTH(appearance_data) > 0") or die $dbHandle->errstr;
318 $statementHandle->execute() or die $statementHandle->errstr;
320 while (my @row = $statementHandle->fetchrow_array)
327 print "<viewing: [@ARGV]>\n" if $debug;
329 # Prepare the SELECT statement: grab all non-empty appearance_data and associated object ids.
330 my $statementHandle = $dbHandle->prepare("SELECT object_id, appearance_data FROM tangible_objects WHERE (LENGTH(appearance_data) > 0) AND object_id = ?") or die $dbHandle->errstr;
332 for (; defined($ARGV[0]); shift @ARGV)
334 $statementHandle->execute($ARGV[0]) or die $statementHandle->errstr;
335 my @row = $statementHandle->fetchrow_array;
339 print "object id [$ARGV[0]] has no customization data.\n";
348 # ----------------------------------------------------------------------
350 sub convertOracleDumpToString
352 my $oracleDumpString = shift;
355 # remove header info.
356 $oracleDumpString =~ s/^\s*(\d+)?.*:\s*//;
359 while (length($oracleDumpString) > 0)
361 if ($oracleDumpString =~ s/^(\d+)(\s*,\s*)?//)
363 $newString .= chr($1);
367 print STDERR
"convertOracleDumpToString: ", length($oracleDumpString), " characters remain: [val=", ord(substr($oracleDumpString,0,1)), "].\n";
375 # ----------------------------------------------------------------------
377 sub extractAppearanceDataFromFile
380 open($dumpFile, '< ' . $dumpFileName) or die "failed to open dump file [$dumpFileName]: $!";
385 # Check if we're dealing with the proper entry.
386 if ($entry == $dumpFileEntryNumber)
389 my $appearanceData = convertOracleDumpToString
($_);
391 close($dumpFile) or die "Failed to close dump file: $!";
392 return $appearanceData;
399 close($dumpFile) or die "Failed to close dump file: $!";
400 die "Entry [$dumpFileEntryNumber] does not exist in file [$dumpFileName] with [$entry] entries.";
403 # ----------------------------------------------------------------------
405 sub updateAppearanceData
408 my $objectId = shift;
409 my $appearanceData = shift;
412 my $rowCount = $dbHandle->do("UPDATE tangible_objects SET appearance_data=? WHERE object_id=$objectId", undef, $appearanceData) or die $dbHandle->errstr;
413 $dbHandle->commit() or die $dbHandle->errstr;
414 print "[$rowCount] rows updated.\n";
417 # ----------------------------------------------------------------------
422 my $appearanceData = extractAppearanceDataFromFile
();
423 die "Could not extract appearance data from 1-line dump file.\n" if !defined($appearanceData);
425 # Update the database.
426 die "Expecting objectId at end of line.\n" if (@ARGV != 1);
428 my $objectId = $ARGV[0];
429 updateAppearanceData
($objectId, $appearanceData);
432 # ----------------------------------------------------------------------
436 # Open the database connection.
437 $dbHandle = DBI
->connect("dbi:Oracle:$databaseName", $userName, $password, { RaiseError
=> 1, AutoCommit
=> 0 });
438 error
("failed to open database: [$DBI::errstr]") if !defined($dbHandle);
439 print "<connection: opened connection to database [$databaseName] as user [$userName] successfully.>\n" if $debug;
442 # ----------------------------------------------------------------------
444 sub disconnectDatabase
446 # Close the database connection.
447 my $returnCode = $dbHandle->disconnect or warn $dbHandle->errstr;
448 print "<disconnect: return code $returnCode>\n" if $debug;
451 # ======================================================================
452 # Program Starts Here
453 # ======================================================================
461 Customization
::initializeCustomization
($customizationIdManagerFilename);
464 elsif ($modeIsChange)
470 die "Major mode is neither viewing or changing.\n";
473 disconnectDatabase
();
476 # ======================================================================