var util = require("util");
var config = require("./configure.js");
-var async = require("async");
-var MySQLPool = new require("./mysql_pool.js");
-var pool = new MySQLPool({
- host : config.db_host,
- user : config.db_user,
- password : config.db_password,
- port : config.db_port,
- database : config.db_name,
- });
-
-if("name_hash" in config.alias)
-{
- if(config.alias["name_hash"].type != "unsignednumber")
- throw "name_hashの型はunsignednumberでなければなりません";
-}else{
- throw "name_hashが存在しません";
-}
-
-if("name" in config.alias)
-{
- if(config.alias["name"].type != "text")
- throw "nameの型はtextでなければなりません";
-}else{
- throw "nameが存在しません";
-}
-
-if("password" in config.alias)
-{
- if(config.alias["password"].type != "password")
- throw "nameの型はpasswordでなければなりません";
-}else{
- throw "passwordが存在しません";
-}
-
-if("lastmodified" in config.alias)
-{
- if(config.alias["lastmodified"].type != "datetime")
- throw "lastmodifiedの型はtextでなければなりません";
-}else{
- throw "lastmodifiedが存在しません";
-}
-
-async.waterfall([
- function(next){
- var query = GetDropTableQuery("profilelist");
- pool.query(query,null,next);
- },
- function(result,next){
- var query = GetCreateQuery(config.alias,"profilelist");
- pool.query(query,null,next);
- },
- function(result,next){
- var query = GetDropTableQuery("ipbanlist");
- pool.query(query,null,next);
- },
- function(result,next){
- var def = {
- ip:{
- type : "text",
- length : 64,
- primary : true,
- },
- type:{
- type : "text",
- length : 1,
- primary : true,
- },
- };
- var query = GetCreateQuery(def,"ipbanlist");
- pool.query(query,null,next);
- },
- function(result,next){
- var query = GetDropTableQuery("rooms");
- pool.query(query,null,next);
- },
- function(result,next){
- var def = {
- number:
- {
- type : "unsignednumber",
- length:2,
- isnotempty : true,
+module.exports = function(callback){
+ var async = require("async");
+
+ var MySQLPool = new require("./mysql_pool.js");
+ var pool = new MySQLPool({
+ host : config.db_host,
+ user : config.db_user,
+ password : config.db_password,
+ port : config.db_port,
+ database : config.db_name,
+ });
+
+ if("name_hash" in config.alias)
+ {
+ if(config.alias["name_hash"].type != "unsignednumber")
+ throw "name_hashの型はunsignednumberでなければなりません";
+ }else{
+ throw "name_hashが存在しません";
+ }
+
+ if("name" in config.alias)
+ {
+ if(config.alias["name"].type != "text")
+ throw "nameの型はtextでなければなりません";
+ }else{
+ throw "nameが存在しません";
+ }
+
+ if("password" in config.alias)
+ {
+ if(config.alias["password"].type != "password")
+ throw "nameの型はpasswordでなければなりません";
+ }else{
+ throw "passwordが存在しません";
+ }
+
+ if("lastmodified" in config.alias)
+ {
+ if(config.alias["lastmodified"].type != "datetime")
+ throw "lastmodifiedの型はtextでなければなりません";
+ }else{
+ throw "lastmodifiedが存在しません";
+ }
+
+ async.waterfall([
+ function(next){
+ var query = GetDropTableQuery("profilelist");
+ pool.query(query,null,next);
+ },
+ function(result,next){
+ var query = GetCreateQuery(config.alias,"profilelist");
+ pool.query(query,null,next);
+ },
+ function(result,next){
+ var query = GetDropTableQuery("ipbanlist");
+ pool.query(query,null,next);
+ },
+ function(result,next){
+ var def = {
+ ip:{
+ type : "text",
+ length : 64,
primary : true,
},
- password:{
- type : "text",
- length : 16,
- },
- hiddenlog:{
- type : "bool",
- },
- };
- var query = GetCreateQuery(def,"rooms");
- pool.query(query,null,next);
- },
-],function(err){
- if(err != null)
- console.log(err);
- process.exit();
-});
-
+ type:{
+ type : "text",
+ length : 1,
+ primary : true,
+ },
+ };
+ var query = GetCreateQuery(def,"ipbanlist");
+ pool.query(query,null,next);
+ },
+ function(result,next){
+ var query = GetDropTableQuery("rooms");
+ pool.query(query,null,next);
+ },
+ function(result,next){
+ var def = {
+ number:
+ {
+ type : "unsignednumber",
+ length:2,
+ isnotempty : true,
+ primary : true,
+ },
+ password:{
+ type : "text",
+ length : 16,
+ },
+ hiddenlog:{
+ type : "bool",
+ },
+ };
+ var query = GetCreateQuery(def,"rooms");
+ pool.query(query,null,next);
+ },
+ ],callback);
+}
function GetDropTableQuery(tablename)
{
app.use(express.errorHandler()); \r
});\r
\r
-var server = http.createServer(app).listen(config.port);\r
-console.log("Express server listening on port %d in %s mode", config.port, app.settings.env);\r
+var async = require("async");\r
+var fs = require("fs");\r
\r
-require("./chat")(app,server,express,sessionStore);\r
-\r
-if(config.enable_profile)\r
- require("./profile")(app);\r
+async.waterfall([\r
+ function(next){\r
+ fs.exists("inited",function(exists){\r
+ next(null,exists);\r
+ });\r
+ },\r
+ function(exists,next){\r
+ if(exists)\r
+ next(null);\r
+ else\r
+ fs.open("inited","a",function(err,fd){\r
+ fs.closeSync(fd);\r
+ var init = require("./init");\r
+ init(next);\r
+ });\r
+ }\r
+ ],function(err){\r
+ if(err != null)\r
+ {\r
+ console.log(err);\r
+ process.exit();\r
+ }\r
+ var server = http.createServer(app).listen(config.port);\r
+ console.log("Express server listening on port %d in %s mode", config.port, app.settings.env);\r
+ \r
+ require("./chat")(app,server,express,sessionStore);\r
+ \r
+ if(config.enable_profile)\r
+ require("./profile")(app);\r
+ });\r