Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

bbs.c 10.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/******************************************************************************
BBS.C        Generic BBS functions.

    Copyright 1993 - 2000 Paul J. Sidorsky

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as
    published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
Deucе's avatar
Deucе committed
17
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354

This module contains the NODES and PAGE commands, and functions which front-end
the BBS-specific calls.
******************************************************************************/

#include "top.h"

/* bbs_useron() - Displays who is logged on to the BBS.  (NODES command.)
   Parameters:  endpause - TRUE to pause after displaying the list.
   Returns:  Nothing.
   Notes:  The code to support the endpause flag has been removed so the
           parameter is effectively unused.
*/
void bbs_useron(char endpause)
{
XINT d, count, key, res = 1; /* Counters, keypress holder, result code. */
char nonstop = 0; /* Nonstop mode flag. */
bbsnodedata_typ nodeinf; /* Buffer for BBS data. */
node_idx_typ nodedat; /* Buffer for NODEIDX data. */

/* Set up and display the header. */
// Should be an assertion
if (bbs_call_setexistbits != NULL)
    (*bbs_call_setexistbits)(&nodeinf);
bbs_useronhdr(&nodeinf);

check_nodes_used(FALSE);

for (d = 0, count = 0; d < MAXNODES; d++)
	{
    /* Show a more prompt if 20 nodes have been shown. */
    if ((count % 20 == 0) && !nonstop && count > 0) // Use screenlength!
        {
        nonstop = moreprompt();
        if (nonstop == -1)
            {
            break;
            }
    	}

	memset(&nodeinf, 0, sizeof(bbsnodedata_typ) - 2);
	memset(&nodedat, 0, sizeof(node_idx_typ));
    if (activenodes[d])
    	{
        /* If the node is active in TOP then use the NODEIDX data.  This is
           done because it is faster and more reliable. */
        res = get_node_data(d, &nodedat);
        if (!res)
        	{
            fixname(nodeinf.handle, nodedat.handle);
	        fixname(nodeinf.realname, nodedat.realname);
    	    nodeinf.node = d;
        	nodeinf.speed = nodedat.speed;
	        strcpy(nodeinf.location, nodedat.location);
            strcpy(nodeinf.statdesc,
				   top_output(OUT_STRING, getlang("NodeStatus")));
	        nodeinf.quiet = nodedat.quiet;
    	    nodeinf.gender = nodedat.gender;
        	nodeinf.hidden = 0;
        	}
        }
    else
    	{
        /* Load the data from the BBS's useron file. */
        if (bbs_call_loaduseron)
            res = (*bbs_call_loaduseron)(d, &nodeinf);
        if (res == -2)
        	{
            break;
            }
        }

    /* Display the appropriate information for the node. */
    if (!nodeinf.hidden && !res)
    	{
        if (nodeinf.existbits & NEX_NODE)
        	{
            itoa(nodeinf.node, outnum[0], 10);
            top_output(OUT_SCREEN, getlang("NodesNodeDisp"), outnum[0]);
            }
        if ((nodeinf.existbits & NEX_HANDLE) && cfg.usehandles)
        	{
            top_output(OUT_SCREEN, getlang("NodesHandleDisp"),
                       nodeinf.handle);
            }
        if ((nodeinf.existbits & NEX_REALNAME) && !cfg.usehandles)
            {
            top_output(OUT_SCREEN, getlang("NodesRealNameDisp"),
                       nodeinf.realname);
            }
        if (nodeinf.existbits & NEX_SPEED)
        	{
            ltoa(nodeinf.speed, outnum[0], 10);
            top_output(OUT_SCREEN, getlang("NodesSpeedDisp"), outnum[0]);
            }
        if (nodeinf.existbits & NEX_LOCATION)
        	{
            top_output(OUT_SCREEN, getlang("NodesLocationDisp"),
                       nodeinf.location);
            }
        if (nodeinf.existbits & NEX_STATUS)
        	{
            top_output(OUT_SCREEN, getlang("NodesStatusDisp"),
                       nodeinf.statdesc);
            }
        if (nodeinf.existbits & NEX_PAGESTAT)
            {
            top_output(OUT_SCREEN, getlang("NodesPageStatDisp"),
                       nodeinf.quiet ? getlang("PageStatNo") :
                       getlang("PageStatYes"));
            } // Also add GENDER and NUMCALLS!
        top_output(OUT_SCREEN, getlang("NodesListEndLine"));
        count++;
        }
    }

if (endpause)
	{
    // Language-enabled press-a-key later.
//    top_output(OUT_SCREEN, getlang("NodesListAfterKey"));
    }

}

/* bbs_page() - Sends a message from TOP to a user on the BBS (PAGE cmd.)
   Parameters:  nodenum - Node number to page, or -1 to prompt user.
                pagebuf - String containing the page text, or NULL to use the
                          editor.
   Returns:  Nothing.
*/
void bbs_page(XINT nodenum, unsigned char *pagebuf)
{
/* Final page buffer, string conversion of node number. */
unsigned char *pagemsg = NULL, pnode[6];
XINT pagenode, pres; /* Final node to page, result code. */
bbsnodedata_typ pnodeinf; /* Buffer for BBS data. */
node_idx_typ pnodedat; /* Buffer for NODEIDX data. */

/* Allocate an edit buffer if no string was passed. */
if (pagebuf == NULL)
    {
    pagemsg = malloc(1601);
    if (!pagemsg)
        {
        top_output(OUT_SCREEN, getlang("NoMemToPage"));
        return;
        }
    }

if (nodenum < 0)
    {
    /* Prompt the user for a node number if none was passed. */
    do
        { // Need to change this back to the old way...
        top_output(OUT_SCREEN, getlang("PageWho"));
        od_input_str(pnode, 5, '0', '?');
        if (pnode[0] == '?')
            {
            bbs_useron(FALSE);
            top_output(OUT_SCREEN, "@c");
            }
        }
    while(pnode[0] == '?');

    pagenode = atoi(pnode);
    if (!pnode[0])
        {
        top_output(OUT_SCREEN, getlang("PageAborted"));
        dofree(pagemsg);
        return;
        }
    itoa(pagenode, pnode, 10);
    if (pagenode < 1 || pagenode >= cfg.maxnodes)
        {
        itoa(cfg.maxnodes - 1, outnum[0], 10);
        top_output(OUT_SCREEN, getlang("InvalidNode"), outnum[0]);
        dofree(pagemsg);
        return;
        }
    }
else
    {
    pagenode = nodenum;
    itoa(nodenum, pnode, 10);
    }

pres = 0;
memset(&pnodeinf, 0, sizeof(bbsnodedata_typ) - 2);
memset(&pnodedat, 0, sizeof(node_idx_typ));
if (activenodes[pagenode])
	{
    /* If the user's in TOP, use the NODEIDX data instead. */
    pres = get_node_data(pagenode, &pnodedat);
    pnodeinf.quiet = pnodedat.quiet;
    }
else
	{
    pres = 1;
    /* Load the user's data from the BBS. */
    if (bbs_call_loaduseron)
        pres = (*bbs_call_loaduseron)(pagenode, &pnodeinf);
    if (pres)
    	{
		pnodeinf.hidden = 1;
        }
    }

/* Page is aborted if node is hidden or not in use, or if user is in Quiet
   mode. */
if (pnodeinf.hidden)
	{
    top_output(OUT_SCREEN, getlang("NodeNotInUse"), pnode);
    dofree(pagemsg);
    return;
	}
if (pnodeinf.quiet)
	{
    top_output(OUT_SCREEN, getlang("NodeDND"), pnode);
    dofree(pagemsg);
    return;
    }

if (pagebuf == NULL)
    {
    /* Call the editor if no page was passed. */
    memset(pagemsg, 0, 1601);
    (*bbs_call_pageedit)(pagenode, pagemsg); // use retval later
    }
else
    {
    pagemsg = pagebuf;
    }

/* Performs the actual paging of the user if that function is available. */
if (bbs_call_page != NULL)
    {
    if ((*bbs_call_page)(pagenode, pagemsg))
        {
        top_output(OUT_SCREEN, getlang("Paged"), pnode);
        od_log_write(top_output(OUT_STRING, getlang("LogSentPage"),
                     pnode));
        }
    }
else
    {
    top_output(OUT_SCREEN, getlang("CantPage"), pnode);
    od_log_write(top_output(OUT_STRING, getlang("LogCantPage"), pnode));
    }

// Possible else & case for errorcodes

/* Free the edit buffer if it was used. */
if (pagebuf == NULL)
    {
    dofree(pagemsg);
    }

}

/* bbs_useronhdr() - Shows the header for the NODES command.
   Parameters:  ndata - Pointer to the BBS node data being used.
   Returns:  Nothing.
   Notes:  Only the existbits are used from ndata.  The buffer pointed to
           by ndata should first be initialized using a call to the function
           pointed to by bbs_call_setexistbits.
*/
void bbs_useronhdr(bbsnodedata_typ *ndata)
{

top_output(OUT_SCREEN, getlang("NodesHdrPrefix"));

/* Show only the desired fields. */
if (ndata->existbits & NEX_NODE)
    {
    top_output(OUT_SCREEN, getlang("NodesNodeHdr"));
    }
if ((ndata->existbits & NEX_HANDLE) && cfg.usehandles)
    {
    top_output(OUT_SCREEN, getlang("NodesHandleHdr"));
    }
if ((ndata->existbits & NEX_REALNAME) && !cfg.usehandles)
    {
    top_output(OUT_SCREEN, getlang("NodesRealNameHdr"));
    }
if (ndata->existbits & NEX_SPEED)
    {
    top_output(OUT_SCREEN, getlang("NodesSpeedHdr"));
    }
if (ndata->existbits & NEX_LOCATION)
    {
    top_output(OUT_SCREEN, getlang("NodesLocationHdr"));
    }
if (ndata->existbits & NEX_STATUS)
    {
    top_output(OUT_SCREEN, getlang("NodesStatusHdr"));
    }
if (ndata->existbits & NEX_PAGESTAT)
    {
    top_output(OUT_SCREEN, getlang("NodesPageStatHdr"));
    } // Also add GENDER and NUMCALLS!

top_output(OUT_SCREEN, getlang("NodesHdrSuffix"));
top_output(OUT_SCREEN, getlang("NodesSepPrefix"));

/* Show separators for the desired fields. */
if (ndata->existbits & NEX_NODE)
    {
    top_output(OUT_SCREEN, getlang("NodesNodeSep"));
    }
if ((ndata->existbits & NEX_HANDLE) && cfg.usehandles)
    {
    top_output(OUT_SCREEN, getlang("NodesHandleSep"));
    }
if ((ndata->existbits & NEX_REALNAME) && !cfg.usehandles)
    {
    top_output(OUT_SCREEN, getlang("NodesRealNameSep"));
    }
if (ndata->existbits & NEX_SPEED)
    {
    top_output(OUT_SCREEN, getlang("NodesSpeedSep"));
    }
if (ndata->existbits & NEX_LOCATION)
    {
    top_output(OUT_SCREEN, getlang("NodesLocationSep"));
    }
if (ndata->existbits & NEX_STATUS)
    {
    top_output(OUT_SCREEN, getlang("NodesStatusSep"));
    }
if (ndata->existbits & NEX_PAGESTAT)
    {
    top_output(OUT_SCREEN, getlang("NodesPageStatSep"));
    } // Also add GENDER and NUMCALLS!

top_output(OUT_SCREEN, getlang("NodesSepSuffix"));

}