背景:
阅读文章

mud兼容tomud客户端实现步骤

[日期:2008-12-25] 来源:  作者: [字体: ]
一、在 include 目录下加入 tomud.h 文件,文件内容如下:
Copy code
#define TMI(x) (""+x+"")

#define TMA ""
#define TMB ""
#define INFO TMI
#define HEND sprintf("%c",18)

#define PTEXT(x) TMI("ptext "+x)
#define ALERT(x) TMI("alert "+x)
#define MTEXT(x) TMI("ptext "+x)
#define L_ITEM(x) RANK_D->new_short(x)
#define L_ICON(x) TMI("licon "+x)
#define CLEAN0 TMI("lbclear0")
#define ADD0(x) TMI("lbadd0 "+L_ITEM(x)+";")
#define REM0(x) TMI("lbrem0 "+L_ITEM(x)+";")
#define CLEAN1 TMI("lbclear1")
#define ADD1(x) TMI("lbadd1 "+L_ITEM(x)+";")
#define REM1(x) TMI("lbrem1 "+L_ITEM(x)+";")
#define CLEAN2 TMI("lbclear2")
#define ADD2(x) TMI("lbadd2 "+L_ITEM(x)+";")
#define REM2(x) TMI("lbrem2 "+L_ITEM(x)+";")


二、在 include 目录下的 globals.h 里添加代码 #include "tomud.h"
// 以下所有修改内容仅注意修改包含 tomud 字符的地方
三、在 master.c 文件里添加如下内容:
Copy code

// Master.c
//
// For ES II mudlib
// Original from Lil
// Rewritten by Annihilator (11/07/94)
// Modified by Xiang for XKX (12/15/95)
// Updated by Doing Lu for hell (2K)

#pragma optimize
#pragma save_binary

#define BIG5_PORT               4000
#define TOMUD_PORT               6000 // 这里为 tomud 设置专用连接端口 6000
#define TRACE_DETAIL_LENGTH_LIMIT     300
#define SPRINTF_OVERFLOW           65535

#include <ansi.h>
#include <config.h>
#include <localtime.h>


object connect(int port)
{
    object login_ob;
    mixed err;
 
    err = catch(login_ob = new(LOGIN_OB));

    if (err)
    {
          write("现在有人正在修改使用者连线部份的程式,请待会再来。\n");
          write(err);
          destruct(this_object());
    }
   
    if (port == BIG5_PORT)
          login_ob->set_temp("big5", 1);
         
    else
    if (port == TOMUD_PORT)     // 这里是判断是否是 tomud 专用端口连接  
          // 设置TOMUD用户的连接标记,配合 logind.c 判断
          login_ob->set_temp("tomud", 1);          
    return login_ob;
}

四、logind.c 文件里做以下修改(以hell的logind.c为例)

Copy code
void logon(object ob)
{
    object *usr, *login_usr;
    int i, ip_num, wiz_cnt, ppl_cnt, login_cnt;
    int iplimit;
    int user_num;
    int now_time;
    string msg;
    mapping temp_time;
    string *counter = ({});
    string ipname;

    if (uptime() < 30)
    {
          write(sprintf("%s正在启动过程中,请稍候再来。\n", LOCAL_MUD_NAME()));
          destruct(ob);
          return;
    }
   
    now_time = time() & 0xFFFFFFFE;
    if (BAN_D->is_banned(query_ip_number(ob)) == 1)
    {
          write("你的地址在本 MUD 不受欢迎。\n");
          destruct(ob);
          return;
    }

    if (mapp(temp_time = blocks[query_ip_number(ob)]))
    {
          if (now_time - temp_time["time"] < temp_time["punish"])
          {
                write(temp_time["reason"] + "请过" +
                    appromix_time(temp_time["time"] + temp_time["punish"] - now_time) + "再尝试连线。\n");
                destruct(ob);
                return;
          }
          remove_blocks(query_ip_number(ob));
    }
   
    login_usr = filter_array(children(LOGIN_OB), (: query_ip_number($1) == $2 :), query_ip_number(ob));

    if (sizeof(login_usr) > 20)
    {
          blocks_ip(query_ip_number(ob), 1800, "您的IP产生了大量废弃连接!");

          for (i = 0; i < sizeof(login_usr); i ++)
                    destruct(login_usr[i]);

          return;
    }
   
    write(ESC "[2J");
    write(color_filter(read_file(WELCOME)));

    catch(MUDLIST_CMD->main());
    UPTIME_CMD->main();

    // 和tomud相关的
    if (ob->query_temp("tomud"))
          write(ALERT("经典文字MUD游戏『终极地狱』,群号『46892543』,本游戏为免费游戏!$$" +
              "请到 [url]http://www.52mud.com[/url] 浏览本游戏主页和论坛、新闻。$$"+
              "如果有任何疑问,请到本游戏论坛专区提问。$$"));

    if (! VERSION_D->is_version_ok() && ! VERSION_D->query_temp("operator"))
          write(HIY "现在本站正在同步版本,如果你不是巫师,请稍候再登录。\n\n" NOR);
    else
    if (REBOOT_CMD->is_rebooting())
          write(HIY "现在本站正在准备重新启动,如果你不是巫师,请稍候再登录。\n\n" NOR);

    usr = users() + filter(children(LOGIN_OB), (: interactive :));
    wiz_cnt = 0;
    ppl_cnt = 0;
    login_cnt = 0;
    iplimit = 0;    
    for (i = 0; i < sizeof(usr); i++)
    {
          ipname = query_ip_number(usr[i]);
          if (member_array(ipname, counter) == -1)
                counter += ({ ipname });
          if (ipname == query_ip_number(ob))
                iplimit++;
          if (base_name(usr[i]) == LOGIN_OB)
                login_cnt++;
          else if (wizardp(usr[i]))
          {
                if (! usr[i]->query("env/invisible")) wiz_cnt++;
          }
          else ppl_cnt++;
    }

    ip_num = atoi(read_file("/adm/etc/ips", 1));
    if (sizeof(counter) > ip_num)
          write_file("/adm/etc/ips", sprintf("%d", sizeof(counter)), 1);
   
#ifndef MULTI_LOGIN  
    if (iplimit > 8)
    {
          write("对不起," + LOCAL_MUD_NAME() + "限制相同ip多重登录。\n");
          destruct(ob);
          return;
    }
#endif
    if (file_size("/adm/etc/players") > 0)
    {
          sscanf(read_file("/adm/etc/players", 1, 1), "%d %d %d",
              player_week, player_day, day);
               
          ip_num = atoi(read_file("/adm/etc/ips", 1));
         
          write(sprintf ("自开站以来最高在线IP数" CYN " %d " NOR
                "个,今日上线 " CYN "%d" NOR " 人次,本周上线 " CYN "%d" NOR " 人次。\n",
                ip_num, player_day, player_week));
    }

    write(sprintf("目前共有 " CYN "%d" NOR " 位巫师、" CYN "%d" NOR " 位玩家"
              "在线上,以及 "CYN "%d" NOR " 位使"
              "用者尝试连线中。\n", wiz_cnt, ppl_cnt, login_cnt));
   
    // 判断用tomud专用端口连接的是否使用的是tomud客户端    
    if (ob->query_temp("tomud"))
    {
          write(TMI("version"));
          input_to("get_version", ob);
    }
    if (! ob->query_temp("big5"))
          write("Select 国标码 GB or き絏 BIG5 (gb/big5):\n");
    else
          write("您的英文名字(新玩家可以选择一喜欢的名字):\n");
         
    input_to("get_id", ob);
}

// 以下部分为判断是否为tomud客户端
protected void get_version(string arg, object ob)
{
    if (! arg || arg[0..3] != "2060")
    {
          write(HIY "请从下列地址下载Tomud客户端\n" NOR);
          write(HIG "   [url]http://www.52mdu.com[/url]\n" NOR);
          write(HIY "或使用Zmud客户端选择2000端口重新连接。\n\n" NOR);
          destruct(ob);
          return;
    }
    input_to("get_id", ob);
}
// 进入mud时候做一些设置
varargs void enter_world(object ob, object user, int silent)
{
    object cloth, shoe, room, login_ob;
    string startroom;
    string ipname;
    mapping marry;
    object *users;

    if (! is_root(previous_object()))
          return;

    user->set_temp("link_ob", ob);
    ob->set_temp("body_ob", user);
    ob->set("registered", user->query("registered"));
    user->set_temp("time", time());
    user->set("env/show_reply", "all");
    if (ob->query_temp("big5"))
          user->set_temp("big5", 1);

    // 设置tomud用户标志
    if (ob->query_temp("tomud"))
          user->set_temp("tomud", 1);
    if (interactive(ob)) exec(user, ob);

    write("\n目前权限:" + wizhood(user) + "\n");

    user->setup();
    if (user->query("age") == 14)
    {
          user->set("food", user->max_food_capacity());
          user->set("water", user->max_water_capacity());
    }

    // In case of new player, we save them here right aftre setup
    // compeleted.
    // 在这里创建一个数据库记录
#ifdef LONELY_IMPROVED
    if (user->query_temp("newplayer") && DB_SAVE)
    {
          if (! DATABASE_D->query_db_status())
              DATABASE_D->connect_to_database();
             
        DATABASE_D->db_new_player(ob, user);
    }
#endif
    user->save();
    user->set("last_save", time());
    ob->save();

    // check the user
    UPDATE_D->check_user(user);

    if (wizhood(user) == "(player)")
    {
          if (user->query("class") == "bonze")
          {
                if (user->query("gender") == "女性")
                {
                    cloth = new("/clone/cloth/ni-cloth.c");
                    shoe = new("/clone/cloth/ni-xie.c");
                }
                else
                {
                    cloth = new("/clone/cloth/seng-cloth.c");
                    shoe = new("/clone/cloth/seng-xie.c");
                }
          } else
          {
                if (user->query("class") == "taoist")
                {
                    if (user->query("gender") == "女性")
                    {
                          cloth = new("/clone/cloth/daogu-cloth.c");
                          shoe = new("/clone/cloth/dao-xie.c");
                    } else
                    {
                          cloth = new("/clone/cloth/dao-cloth.c");
                          shoe = new("/clone/cloth/dao-xie.c");
                    }
                } else
                {
                    if (user->query("gender") == "女性")
                    {
                          shoe = new("/clone/cloth/female-shoe.c");
                          cloth = new(sprintf("/clone/cloth/female%d-cloth.c", 1 + random(8)));
                    } else
                    {
                          shoe = new("/clone/cloth/male-shoe.c");
                          cloth = new(sprintf("/clone/cloth/male%d-cloth.c", 1 + random(8)));
                    }
                }
          }

          cloth->move(user);
          catch(cloth->wear());
          shoe->move(user);
          catch(shoe->wear());
    } else
    {
          if (user->query("gender") == "女性")
          {
                cloth = new("/clone/cloth/yunshang");
                cloth->move(user);
                cloth->wear();
          } else
          {
                cloth = new("/clone/cloth/jinduan");
                shoe = new("/clone/cloth/xianlv");
                cloth->move(user);
                cloth->wear();
                shoe->move(user);
                shoe->wear();
          }
    }

    if (cloth && (! environment(cloth) || ! cloth->query("equipped")))
          destruct(cloth);

    if (shoe && (! environment(shoe) || ! shoe->query("equipped")))
          destruct(shoe);

    if (! silent)
    {
          if (! user->query("registered"))
                write(color_filter(read_file(UNREG_MOTD)));
          else
                write(color_filter(read_file(MOTD)));

          write("你连线进入" + LOCAL_MUD_NAME() + "。\n\n");

          if (! user->query("registered"))
          {
                if (user->is_ghost())
                    user->reincarnate();
                user->set("startroom", REGISTER_ROOM);
          } else
          if (! stringp(user->query("born")))
          {
                if (user->is_ghost())
                    user->reincarnate();
                user->set("startroom", BORN_ROOM);
          }
         
          if ((string)SECURITY_D->get_status(ob->query("id")) != "(player)")
                startroom = WIZARD_ROOM;
         
          else    
          if (user->is_in_prison())
                startroom = user->query_prison();
          else
          if (user->is_ghost())
                startroom = DEATH_ROOM;
          else
          if (! stringp(startroom = user->query("startroom")) ||
            file_size(startroom + ".c") < 0)
                startroom = START_ROOM;

          if (! catch(load_object(startroom)))
                user->move(startroom);
          else
          {
                user->move(START_ROOM);
                startroom = START_ROOM;
                user->set("startroom", START_ROOM);
          }
          tell_room(startroom, user->query("name") +
                "连线进入这个世界。\n", ({user}));
    }

    login_ob = new(LOGIN_OB);
    login_ob->set("id", user->query("id"));
    login_ob->restore();
    if (login_ob->query("registered"))
    {
          if (! intp(login_ob->query("login_times")))
          {
                write(NOR "\n你是第一次光临" + LOCAL_MUD_NAME() + "。\n");
                login_ob->set("login_times", 1);
                // show rules
          } else
          {
                login_ob->add("login_times", 1);
                write("\n你上次光临" + LOCAL_MUD_NAME() + "是 " + HIG +
                    ctime(login_ob->query("last_on")) + NOR + " 从 " + HIR +
                    login_ob->query("last_from") + NOR + " 连接的。\n");
          }
    }

    destruct(login_ob);

    if (!(wizardp(user)&&user->query("env/no_login_msg")))
    CHANNEL_D->do_channel(this_object(), "sys",
          sprintf("%s(%s)由%s连线进入。",
          user->name(), user->query("id"),
          (ipname = query_ip_number(user)) ? ipname : "未知地点"));

#ifdef LONELY_IMPROVED    
    DATABASE_D->db_set_player(user->query("id"), "online", 1);
    DATABASE_D->db_set_player(user->query("id"), "last_station", LOCAL_STATION);
#endif
   
#if INSTALL_EXAMINE
    EXAMINE_D->examine_player(user);
#endif

    if (day ==6 && day2num[ctime(time())[0..2]] == 7)
          player_week = 0;
    if (day != day2num[ctime(time())[0..2]])
    {
          player_day = 0;
          day = day2num[ctime(time())[0..2]];
    }
    write_file("/adm/etc/players", sprintf( "%d %d %d", player_week + 1, player_day + 1, day), 1);
     
    if (wizhood(user) != "(admin)" &&
        EXAMINE_D->query("log_by/" + user->query("id")))
          user->start_log();

    // notice user the user of this mud
    NEWS_D->prompt_user(user);
    ANALECTA_D->prompt_user(user);
    TOPTEN_D->topten_checkplayer(user);    
    if (mapp(marry = user->query("couple")) && sizeof(marry))
    {
          string tmpstr, tmpstr1;
          object couple_ob = find_player(marry["couple_id"]);
          if (couple_ob)
        {
              if ((string)user->query("gender") != "男性")
              {
                  tmpstr1 = "夫君";
                  tmpstr = "爱妻";
                }
              else
              {
                    tmpstr1 = "爱妻";
                    tmpstr = "夫君";
                }
              write(sprintf(WHT HIM "\n你的%s%s已经在这等了你好久了,快去找%s吧。。。\n" NOR,
                      tmpstr1, couple_ob->name(), gender_pronoun(couple_ob->query("gender"))));
              tell_object(couple_ob, sprintf(WHT HIM "\n你的%s%s抑制不住对你的思念跑来看你啦,快去和%s打个招呼吧。。。\n" NOR,
                                  tmpstr,user->name(),gender_pronoun(user->query("gender"))));
        }
    }

    if ((user->query("qi") < 0 || user->query("jing") < 0) && living(user))
          user->unconcious();

    // 以下部分为在tomud用户的客户端里添加显示人物
    users = filter_array(users(), (: $1->query_temp("tomud") :));
    message("system", ADD2(user), users);
    if (user->query_temp("tomud"))
    {
          foreach (object player in users())
                tell_object(user, ADD2(player));
          // 激发tomud客户端中的物品显示等
          user->force_me("inventory");
          user->force_me("wear all");
          user->force_me("cmdbar");
    }
}

varargs void reconnect(object ob, object user, int silent)
{
    user->set_temp("link_ob", ob);
    ob->set_temp("body_ob", user);
   
    if (ob->query_temp("big5"))
          user->set_temp("big5", 1);
    else  
          user->delete_temp("big5");
   
    // 重新连接判断是否是用tomud客户端,不是则消除使用tomud客户端标记    
    if (ob->query_temp("tomud"))
          user->set_temp("tomud", 1);
    else  
          user->delete_temp("tomud");

    exec(user, ob);

    user->reconnect();
    if (! silent && (! wizardp(user) || ! user->query("env/invisible"))) {
          tell_room(environment(user), user->query("name") + "重新连线回到这个世界。\n",
          ({user}));
    }
   
    // 激发tomud客户端用户物品栏等的显示
    if (user->query_temp("tomud"))
    {
          user->force_me("look");
          user->force_me("inventory");
          user->force_me("cmdbar");
    }
#ifdef LONELY_IMPROVED    
    DATABASE_D->db_set_player(user->query("id"), "online", 1);
#endif
   
    if (! (wizardp(user) && user->query("env/no_login_msg")))
    CHANNEL_D->do_channel( this_object(), "sys",
          sprintf("%s(%s)由%s重新连线进入。", user->query("name"),
                user->query("id"), query_ip_number(user)));
}

收藏 推荐 打印 | 录入:sbso | 阅读:
相关内容      
本文评论   [发表评论]   全部评论 (0)
内容推送
52mud提供
收听52mud微信公众平台
52mud官方微信公众平台
热门评论