home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / top2src.zip / CHANGE.C < prev    next >
C/C++ Source or Header  |  2000-07-13  |  7KB  |  227 lines

  1. /******************************************************************************
  2. CHANGE.C     CHANGE command processor.
  3.  
  4.     Copyright 1993 - 2000 Paul J. Sidorsky
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License, version 2, as
  8.     published by the Free Software Foundation.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  
  19. Processes the CHANGE command to change user settings.
  20. ******************************************************************************/
  21.  
  22. #include "top.h"
  23.  
  24. /* change_proc() - CHANGE command processor.
  25.    Parameters:  None.
  26.    Returns:  Nothing.
  27. */
  28. void change_proc(void)
  29. {
  30. char tmpstr[256]; /* Temporary output buffer. */
  31.  
  32. /* Change user handle. */
  33. if (checkcmdmatch(get_word(1), getlang("CmdsChangeHandle")) > 0)
  34.     {
  35.     char thand[31]; /* Temporary handle buffer. */
  36.  
  37.     if (!cfg.allowhandlechange)
  38.         {
  39.         top_output(OUT_SCREEN, getlang("ChgHandNotAllowed"));
  40.         return;
  41.         }
  42.  
  43.     if (user.security < cfg.handlechgsec)
  44.         {
  45.         top_output(OUT_SCREEN, getlang("NoAccChgHandle"));
  46.         return;
  47.         }
  48.  
  49.     memset(thand, 0, 31);
  50.  
  51.     /* Only continue processing if there's at least three words. */
  52.     if (get_word_char(2, 0))
  53.         {
  54.         strncpy(thand, &word_str[word_pos[2]], 30);
  55.  
  56.         if (check_dupe_handles(thand))
  57.                {
  58.             top_output(OUT_SCREEN, getlang("HandleInUse"));
  59.             return;
  60.             }
  61.  
  62.         fixname(user.handle, thand);
  63.  
  64.         /* Update list of online handles. */
  65.         fixname(handles[od_control.od_node].string, thand);
  66.  
  67.         /* Notify other users. */
  68.         dispatch_message(MSG_HANDLECHG, thand, -1, 0, 0);
  69.  
  70.         /* Save new handle to user and NODEIDX files. */
  71.         save_user_data(user_rec_num, &user);
  72.         fixname(node->handle, thand);
  73.         save_node_data(od_control.od_node, node);
  74.  
  75.         top_output(OUT_SCREEN, getlang("ChangedHandle"), user.handle);
  76.         od_log_write(top_output(OUT_STRING, getlang("LogChangedHandle"),
  77.                      user.handle));
  78.  
  79.         return;
  80.         }
  81.     top_output(OUT_SCREEN, getlang("HandleNotSpecified"));
  82.     return;
  83.     }
  84. /* Change the user's gender. */
  85. if (checkcmdmatch(get_word(1), getlang("CmdsChangeSex")) > 0)
  86.     {
  87.     if (!cfg.allowsexchange)
  88.         {
  89.         top_output(OUT_SCREEN, getlang("ChgSexNotAllowed"));
  90.         return;
  91.         }
  92.  
  93.     if (user.security < cfg.sexchangesec)
  94.         {
  95.         top_output(OUT_SCREEN, getlang("NoAccChgSex"));
  96.         return;
  97.         }
  98.  
  99.     /* Save new information to user file. */
  100.     user.gender = !user.gender;
  101.     save_user_data(user_rec_num, &user);
  102.     top_output(OUT_SCREEN, getlang("ChangedSex"),
  103.                getlang(user.gender ? "Female" : "Male"));
  104.  
  105.     /* Notify other users. */
  106.     if (user.gender)
  107.     {
  108.         strcpy(tmpstr, top_output(OUT_STRINGNF, getlang("Female")));
  109.     }
  110.     else
  111.     {
  112.         strcpy(tmpstr, top_output(OUT_STRINGNF, getlang("Male")));
  113.     }
  114.     dispatch_message(MSG_SEXCHG, tmpstr, -1, 0, 0);
  115.  
  116.     return;
  117.     }
  118. /* Change user's entry message. */
  119. if (checkcmdmatch(get_word(1), getlang("CmdsChangeEMessage")) > 0)
  120.     {
  121.     if (!cfg.allowexmessages)
  122.         {
  123.         top_output(OUT_SCREEN, getlang("ChgEXMsgNotAllowed"));
  124.         return;
  125.         }
  126.  
  127.     if (user.security < cfg.exmsgchangesec)
  128.         {
  129.         top_output(OUT_SCREEN, getlang("NoAccChgEXMsg"));
  130.         return;
  131.         }
  132.  
  133.     /* Clear the message if none is specified. */
  134.     if (!get_word_char(2, 0))
  135.         {
  136.         memset(user.emessage, 0, 81);
  137.         save_user_data(user_rec_num, &user);
  138.         top_output(OUT_SCREEN, getlang("EMessageCleared"));
  139.         return;
  140.         }
  141.  
  142.     /* Save new information to user file. */
  143.     memset(user.emessage, 0, 81);
  144.     strncpy(user.emessage, &word_str[word_pos[2]], 80);
  145.     save_user_data(user_rec_num, &user);
  146.     top_output(OUT_SCREEN, getlang("ChangedEMessage"));
  147.  
  148.     /* Notify other users. */
  149.     dispatch_message(MSG_EXMSGCHG, "\0", -1, 0, 0);
  150.  
  151.     return;
  152.     }
  153. /* Change the user's exit message. */
  154. if (checkcmdmatch(get_word(1), getlang("CmdsChangeXMessage")) > 0)
  155.     {
  156.     if (!cfg.allowexmessages)
  157.         {
  158.         top_output(OUT_SCREEN, getlang("ChgEXMsgNotAllowed"));
  159.         return;
  160.         }
  161.  
  162.     if (user.security < cfg.exmsgchangesec)
  163.         {
  164.         top_output(OUT_SCREEN, getlang("NoAccChgEXMsg"));
  165.         return;
  166.         }
  167.  
  168.     /* Clear the message if none is specified. */
  169.     if (!get_word_char(2, 0))
  170.         {
  171.         memset(user.xmessage, 0, 81);
  172.         save_user_data(user_rec_num, &user);
  173.         top_output(OUT_SCREEN, getlang("XMessageCleared"));
  174.         return;
  175.         }
  176.  
  177.     /* Save new information to user file. */
  178.     memset(user.xmessage, 0, 81);
  179.     strncpy(user.xmessage, &word_str[word_pos[2]], 80);
  180.     save_user_data(user_rec_num, &user);
  181.     top_output(OUT_SCREEN, getlang("ChangedXMessage"));
  182.  
  183.     /* Notify other users. */
  184.     dispatch_message(MSG_EXMSGCHG, "\0", -1, 0, 0);
  185.     return;
  186.     }
  187. /* Toggle dual-window chat mode. */
  188. if (checkcmdmatch(get_word(1), getlang("CmdsChangeChatMode")) > 0)
  189.     {
  190.     /* Dual Window chat mode currently only works with ANSI.  AVATAR
  191.        support not implemented. */
  192.     if (!od_control.user_ansi/* && !od_control.user_avatar*/)
  193.         {
  194.         top_output(OUT_SCREEN, "DualWindowNoGfx");
  195.         return;
  196.         }
  197.     else
  198.         {
  199.         /* Save new information. */
  200.         user.pref1 ^= PREF1_DUALWINDOW;
  201.         save_user_data(user_rec_num, &user);
  202.         top_output(OUT_SCREEN, getlang("ChangedChatMode"),
  203.                    getlang(user.pref1 & PREF1_DUALWINDOW ?
  204.                            "DualWindowChatMode" : "NormalChatMode"));
  205.         return;
  206.         }
  207.     }
  208. /* Toggle channel listed status. */
  209. if (checkcmdmatch(get_word(1), getlang("CmdsChangeListed")) > 0)
  210.     {
  211.     /* Save new information. */
  212.     user.pref2 ^= PREF2_CHANLISTED;
  213.     save_user_data(user_rec_num, &user);
  214.     node->channellisted = (user.pref2 & PREF2_CHANLISTED);
  215.     save_node_data(od_control.od_node, node);
  216.     top_output(OUT_SCREEN, getlang("ChangedListed"),
  217.                getlang(user.pref2 & PREF2_CHANLISTED ? "ChannelListed" :
  218.                "ChannelUnlisted"));
  219.     return;
  220.     }
  221.  
  222. /* Command not recognized, show help file instead. */
  223. show_helpfile("HELPCHG0");
  224.  
  225. return;
  226. }
  227.