/*
 Navicat Premium Data Transfer

 Source Server         : 127.0.0.1
 Source Server Type    : MySQL
 Source Server Version : 50739
 Source Host           : 127.0.0.1:3306
 Source Schema         : mir_name

 Target Server Type    : MySQL
 Target Server Version : 50739
 File Encoding         : 65001

 Date: 11/10/2022 21:31:16
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for charnames
-- ----------------------------
DROP TABLE IF EXISTS `charnames`;
CREATE TABLE `charnames`  (
  `charid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '角色唯一ID',
  `charname` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '角色名称',
  `serverindex` int(11) NULL DEFAULT 0,
  PRIMARY KEY (`charid`) USING BTREE,
  INDEX `Index_charname`(`charname`) USING BTREE,
  INDEX `Index_serverindex`(`serverindex`) USING BTREE
) ENGINE = MyISAM AUTO_INCREMENT = 16777569 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '全局角色名称表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of charnames
-- ----------------------------
INSERT INTO `charnames` VALUES (16777568, '__init_actorid_1', 0);

-- ----------------------------
-- Table structure for filternames
-- ----------------------------
DROP TABLE IF EXISTS `filternames`;
CREATE TABLE `filternames`  (
  `namestr` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '屏蔽词',
  PRIMARY KEY (`namestr`) USING BTREE
) ENGINE = MyISAM CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '名称屏蔽词表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of filternames
-- ----------------------------

-- ----------------------------
-- Table structure for guildnames
-- ----------------------------
DROP TABLE IF EXISTS `guildnames`;
CREATE TABLE `guildnames`  (
  `guildid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '帮会唯一ID',
  `guildname` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '帮会名称',
  `serverindex` int(11) NULL DEFAULT 0,
  PRIMARY KEY (`guildid`) USING BTREE,
  INDEX `Index_guildname`(`guildname`) USING BTREE
) ENGINE = MyISAM AUTO_INCREMENT = 16777266 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '帮会ID以及名称表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Records of guildnames
-- ----------------------------
INSERT INTO `guildnames` VALUES (16777265, '__init_guild_1', 0);

-- ----------------------------
-- Procedure structure for allocnewcharid
-- ----------------------------
DROP PROCEDURE IF EXISTS `allocnewcharid`;
delimiter ;;
CREATE PROCEDURE `allocnewcharid`(in sname varchar(32),in nserverindex integer)
begin
  declare nid integer unsigned default null;
  select charid into nid from charnames where charname = sname and serverindex=nserverindex ;
  if nid is null then
    insert into charnames (charname,serverindex) values (sname,nserverindex);
    select last_insert_id();
  else
    select null;
  end if;
end
;;
delimiter ;

-- ----------------------------
-- Procedure structure for allocnewguildid
-- ----------------------------
DROP PROCEDURE IF EXISTS `allocnewguildid`;
delimiter ;;
CREATE PROCEDURE `allocnewguildid`(in sname varchar(32),in nserverindex integer)
begin
  declare nid integer unsigned default null;
  select guildid into nid from guildnames where guildname = sname and serverindex=nserverindex;
  if nid is null then
    insert into guildnames (guildname,serverindex) values (sname,nserverindex);
    select last_insert_id();
  else
    select null;
  end if;
end
;;
delimiter ;

-- ----------------------------
-- Procedure structure for loadfilternames
-- ----------------------------
DROP PROCEDURE IF EXISTS `loadfilternames`;
delimiter ;;
CREATE PROCEDURE `loadfilternames`()
BEGIN
  select namestr from filternames;
END
;;
delimiter ;

-- ----------------------------
-- Procedure structure for renamechar
-- ----------------------------
DROP PROCEDURE IF EXISTS `renamechar`;
delimiter ;;
CREATE PROCEDURE `renamechar`(in ncharid integer, in snewname varchar(32))
begin
  declare nid integer unsigned default null;
  select idx into nid from charnames where charname = snewname;
  if nid is null then
    update charnames set charname = snewname where idx = ncharid;
    select 0;
  else
    select 1;
  end if;
end
;;
delimiter ;

-- ----------------------------
-- Procedure structure for renameguild
-- ----------------------------
DROP PROCEDURE IF EXISTS `renameguild`;
delimiter ;;
CREATE PROCEDURE `renameguild`(in ncharid integer, in snewname varchar(32))
begin
  declare nid integer unsigned default null;
  select idx into nid from guildnames where guildname = snewname;
  if nid is null then
    update guildnames set guildname = snewname where serverindex = ncharid;
    select 0;
  else
    select 1;
  end if;
end
;;
delimiter ;

-- ----------------------------
-- Procedure structure for v2_allocnewcharid
-- ----------------------------
DROP PROCEDURE IF EXISTS `v2_allocnewcharid`;
delimiter ;;
CREATE PROCEDURE `v2_allocnewcharid`(in sname varchar(32),in nserverindex integer)
begin
  declare nid integer unsigned default null;
  select `charid` into nid from charnames where `serverindex`=0 ;
  if nid is null then
	select null;
  else
	set nid = nid  +1;
    update charnames set `charid`= nid where `serverindex`=0;
    select nid;
  end if;
end
;;
delimiter ;

-- ----------------------------
-- Procedure structure for v2_allocnewguildid
-- ----------------------------
DROP PROCEDURE IF EXISTS `v2_allocnewguildid`;
delimiter ;;
CREATE PROCEDURE `v2_allocnewguildid`(in sname varchar(32),in nserverindex integer)
begin
  declare nid integer unsigned default null;
  select `guildid` into nid from guildnames where `serverindex`=0 ;
  if nid is null then
	select null;
  else
    set nid = nid  +1;
    update guildnames set `guildid`= nid where `serverindex`=0;
    select nid;
  end if;
end
;;
delimiter ;

SET FOREIGN_KEY_CHECKS = 1;
