OK論壇

 找回密碼
 註冊
查看: 7788|回復: 6

[分享] 防雙開函數

[複製鏈接]
  • TA的每日心情
    開心
    2012-10-20 12:31 AM
  • 簽到天數: 305 天

    連續簽到: 94 天

    [LV.8]以壇為家I

    發表於 2011-10-5 00:26:39 | 顯示全部樓層 |閱讀模式
    本帖最後由 rgrg1234 於 2011-10-10 03:17 PM 編輯

    胡亂寫了一個...
    1. script.c
    2. BUILDIN_FUNC(antidoubleopen)
    3. {      
    4.                 struct s_mapiterator* i_pc = mapit_getallusers();
    5.                 int type,fd,m;
    6.                 const char *str=script_hasdata(st, 4)?script_getstr(st,4):"";
    7.         TBL_PC *pl_sd,*sd = map_id2sd(script_getnum(st,2));

    8.         if( sd == NULL )
    9.         {
    10.                                 ShowError("script:antidoubleopen: no player attached\n");
    11.                 return 0;
    12.         }
    13.                 fd=sd->fd ;
    14.                 for( pl_sd = (TBL_PC*)mapit_first(i_pc); mapit_exists(i_pc); pl_sd = (TBL_PC*)mapit_next(i_pc) )
    15.                 {
    16.                         type=script_hasdata(st, 4)?script_getnum(st,3)%2+2:script_getnum(st,3)%2;
    17.                 if((m=map_mapname2mapid(str))< 0 && script_hasdata(st, 4)){
    18.                         ShowWarning("script: antidoubleopen: not mapname variable\n");
    19.                         return 1;
    20.                 }
    21.                         switch(type)
    22.                                     {
    23.                         case 0:
    24.                                                         if(!strcmp(script_getIP(sd->fd),script_getIP(pl_sd->fd))&&sd!=pl_sd){
    25.                                                                 script_pushint(st, 1);
    26.                                                                 return 0;
    27.                                                         }
    28.                                 break;
    29.                                                 case 1:
    30.                                                         if(!strcmp(script_getIP(sd->fd),script_getIP(pl_sd->fd))&&sd!=pl_sd){
    31.                                                         if( fd > 0 )
    32.                                                                 clif_authfail_fd(fd, 15);
    33.                                                         else
    34.                                                                 map_quit(sd);
    35.                                                         script_pushint(st, 1);
    36.                                                         return 0;
    37.                                                         }
    38.                                                                 break;
    39.                                                 case 2:
    40.                                                                 if(!strcmp(script_getIP(sd->fd),script_getIP(pl_sd->fd)) && sd!=pl_sd && sd->bl.m==pl_sd->bl.m && sd->bl.m==map[m].m){
    41.                                                                         script_pushint(st, 1);
    42.                                                                         return 0;
    43.                                                                 }
    44.                                                                 break;
    45.                                                 case 3:
    46.                                                                 if(!strcmp(script_getIP(sd->fd),script_getIP(pl_sd->fd)) && sd!=pl_sd && sd->bl.m==pl_sd->bl.m && sd->bl.m==map[m].m){
    47.                                                                 if( fd > 0 )
    48.                                                                         clif_authfail_fd(fd, 15);
    49.                                                                 else
    50.                                                                         map_quit(sd);
    51.                                                                 script_pushint(st, 1);
    52.                                                                 return 0;
    53.                                                                 }
    54.                                                                 break;
    55.                         default:
    56.                                 ShowError("script:antidoubleopen: 一個未知的參數 (%d).\n",type);
    57.                                 script_pushint(st, -1);
    58.                                 return 0;
    59.                         }
    60.                 }
    61.                 script_pushint(st, 0);
    62.         return 0;
    63. }
    64.         BUILDIN_DEF(antidoubleopen, "ii?"),

    65. clif.c

    66. char* script_getIP(int fd)
    67. {
    68.         if( !session[fd] ) return 0 ;
    69.         return (char*)ip2str(session[fd]->client_addr, NULL);
    70. }
    71. clif.h
    72. char* script_getIP(int fd);
    複製代碼
    *antidoubleopen(<id>,<type>{,"<map name>"})
    1. antidoubleopen(getcharid(3),1,"payon")
    複製代碼
    type 0 用來檢查 該人物為雙開人物返回1  否返回0
    type 1 該人物為雙開人物返回1  否返回0 並踢除該腳色
    回復

    使用道具 舉報

  • TA的每日心情
    慵懶
    2017-2-15 05:18 PM
  • 簽到天數: 476 天

    連續簽到: 1 天

    [LV.9]以壇為家II

    發表於 2011-10-5 03:36:55 | 顯示全部樓層
    挺好的一&#20010;函&#25968;.
    &#35753;&#32553;&#36827;搞得 &#27809;心思看下去了.
    回復 支持 反對

    使用道具 舉報

  • TA的每日心情
    開心
    2012-10-20 12:31 AM
  • 簽到天數: 305 天

    連續簽到: 94 天

    [LV.8]以壇為家I

     樓主| 發表於 2011-10-5 08:28:49 | 顯示全部樓層
    本帖最後由 rgrg1234 於 2011-10-5 09:45 AM 編輯

    回復 2# dreamunreal


        有空幫我測試下吧

    看有無BUG

    我只有稍微測試過
    回復 支持 反對

    使用道具 舉報

  • TA的每日心情
    慵懶
    2017-2-15 05:18 PM
  • 簽到天數: 476 天

    連續簽到: 1 天

    [LV.9]以壇為家II

    發表於 2011-10-5 13:12:43 | 顯示全部樓層
    回復 3# rgrg1234


    我表示.
    我&#27809;&#35265;&#36807; script_getip&#36825;&#20010;函&#25968;.
    回復 支持 反對

    使用道具 舉報

  • TA的每日心情
    慵懶
    2013-7-11 12:09 AM
  • 簽到天數: 118 天

    連續簽到: 1 天

    [LV.6]常住居民II

    發表於 2011-10-5 17:59:24 | 顯示全部樓層
    回復 支持 反對

    使用道具 舉報

  • TA的每日心情
    慵懶
    2017-2-15 05:18 PM
  • 簽到天數: 476 天

    連續簽到: 1 天

    [LV.9]以壇為家II

    發表於 2011-10-6 01:39:07 | 顯示全部樓層
    回復 5# Alopex



    嗲- - 我自己&#20889;了另外一&#20010;函&#25968; return_ipadd.   

    你竟然用scrpt_getip
    回復 支持 反對

    使用道具 舉報

  • TA的每日心情
    開心
    2017-10-13 07:39 AM
  • 簽到天數: 126 天

    連續簽到: 1 天

    [LV.7]常住居民III

    發表於 2014-2-17 16:14:25 | 顯示全部樓層
    rgrg1234 發表於 2011-10-5 08:28 AM
    回復 2# dreamunreal

    測試時發現有時候登入人物會卡在原地不能動
    回復 支持 反對

    使用道具 舉報

    您需要登錄後才可以回帖 登錄 | 註冊

    本版積分規則

    Archiver|手機版|小黑屋|OK討論區

    GMT+8, 2025-6-15 06:02 AM , Processed in 0.078287 second(s), 20 queries , Gzip On.

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回復 返回頂部 返回列表