prot-a-send-async.c 3.04 KB
Newer Older
Per Cederqvist's avatar
Per Cederqvist committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
/*
 * Asynchronous messages in protocol A.
 */

#include <stdio.h>
#include "lyskomd.h"
#include <kom-types.h>
#include <services.h>
#include "async.h"
#include "com.h"
#include "connections.h"
#include "prot-a-send-async.h"
#include "prot-a-output.h"
#include "manipulate.h"
#include "log.h"
#include "isc.h"
#include "mux.h"

static void
async_header(Connection *fp,
	     int   no_of_tokens,
	     Async fnc)
{
    mux_printf(fp, ":%lu %lu", (u_long)no_of_tokens, (u_long)fnc);
}



    
static void
async_trailer(Connection *fp)
{
    mux_putc('\n', fp);
    mux_flush(fp);
}


void
prot_a_async_new_text(Connection *cptr,
		      Text_no	      text_no,
		      Text_stat      *text_s)
{
    async_header(cptr, 16, ay_new_text);
    mux_printf(cptr, " %lu", text_no);
    prot_a_output_text_stat(cptr, text_s);
    async_trailer(cptr);
}


void
prot_a_async_i_am_on(Connection *cptr,
		     Who_info info)
{
    async_header(cptr, 5, ay_i_am_on);
    prot_a_output_who_info(cptr, &info);
    async_trailer(cptr);
}

void
prot_a_async_i_am_off(Connection *cptr,
		      Pers_no pers_no)
{
    async_header(cptr, 1, ay_i_am_off);
    mux_printf(cptr, " %lu", pers_no);
    async_trailer(cptr);
}


void
prot_a_async_logout(Connection *cptr,
		    Pers_no pers_no,
		    Session_no session_no)
{
    async_header(cptr, 2, ay_logout);
    mux_printf(cptr, " %lu %lu", (u_long)pers_no, (u_long)session_no);
    async_trailer(cptr);
}

void
prot_a_async_new_name(Connection *cptr,
		      Conf_no conf_no,
		      String old_name,
		      String new_name)
{
    async_header(cptr, 3, ay_new_name);
    mux_printf(cptr, " %lu", (u_long)conf_no);
    prot_a_output_string(cptr, old_name);
    prot_a_output_string(cptr, new_name);
    async_trailer(cptr);
}

void
prot_a_async_sync_db(Connection *cptr)
{
    async_header(cptr, 0, ay_sync_db);
    async_trailer(cptr);
}

void
prot_a_async_forced_leave_conf(Connection *cptr,
			       Conf_no         conf_no)
{
    async_header(cptr, 1, ay_leave_conf);
    mux_printf(cptr, " %lu", (u_long)conf_no);
    async_trailer(cptr);
}

void
prot_a_async_login(Connection *cptr,
		   Pers_no	   pers_no,
		   int		   session_no)
{
    async_header(cptr, 2, ay_login);
    mux_printf(cptr, " %lu %lu", (u_long)pers_no, (u_long)session_no);
    async_trailer(cptr);
}
    

void
prot_a_async_broadcast(Connection *cptr,
		       Pers_no	       pers_no,
		       String	       message)
{
124
125
    prot_a_async_send_message(cptr, 0, pers_no, message);
#if 0    
Per Cederqvist's avatar
Per Cederqvist committed
126
127
128
129
    async_header(cptr, 2, ay_broadcast);
    mux_printf(cptr, " %lu", (u_long)pers_no);
    prot_a_output_string(cptr, message);
    async_trailer(cptr);
130
#endif
Per Cederqvist's avatar
Per Cederqvist committed
131
}
132

Per Cederqvist's avatar
Per Cederqvist committed
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
void
prot_a_async_rejected_connection(Connection *cptr)
{
    async_header(cptr, 0, ay_rejected_connection);
    async_trailer(cptr);
}
    
void
prot_a_async_send_message(Connection *cptr,
			  Pers_no     recipient,
			  Pers_no     sender,
			  String      message)
{
    async_header(cptr, 3, ay_send_message);
    mux_printf(cptr, " %lu %lu", (u_long)recipient, (u_long)sender);
    prot_a_output_string(cptr, message);
    async_trailer(cptr);
}