1 | /* |
---|
2 | * This file is part of the OLC On-Line Consulting System. |
---|
3 | * It contains procedures for exectuting olc commands. |
---|
4 | * |
---|
5 | * Win Treese |
---|
6 | * Dan Morgan |
---|
7 | * Bill Saphir |
---|
8 | * MIT Project Athena |
---|
9 | * |
---|
10 | * Ken Raeburn |
---|
11 | * MIT Information Systems |
---|
12 | * |
---|
13 | * Tom Coppeto |
---|
14 | * MIT Project Athena |
---|
15 | * |
---|
16 | * Copyright (c) 1988 by the Massachusetts Institute of Technology |
---|
17 | * |
---|
18 | * $Source: /afs/dev.mit.edu/source/repository/athena/bin/olc/clients/tty/t_connect.c,v $ |
---|
19 | * $Author: tjcoppet $ |
---|
20 | */ |
---|
21 | |
---|
22 | #ifndef lint |
---|
23 | static char rcsid[]= "$Header: /afs/dev.mit.edu/source/repository/athena/bin/olc/clients/tty/t_connect.c,v 1.5 1989-08-22 13:53:09 tjcoppet Exp $"; |
---|
24 | #endif |
---|
25 | |
---|
26 | #include <olc/olc.h> |
---|
27 | #include <olc/olc_tty.h> |
---|
28 | |
---|
29 | ERRCODE |
---|
30 | t_grab(Request,flag,hold) |
---|
31 | REQUEST *Request; |
---|
32 | int flag; |
---|
33 | int hold; |
---|
34 | { |
---|
35 | int status; |
---|
36 | char buf[BUFSIZE]; |
---|
37 | int instance; |
---|
38 | |
---|
39 | instance = Request->requester.instance; |
---|
40 | |
---|
41 | if(flag) |
---|
42 | set_option(Request->options,SPLIT_OPT); |
---|
43 | |
---|
44 | status = OGrab(Request); |
---|
45 | switch (status) |
---|
46 | { |
---|
47 | case GRAB_ME: |
---|
48 | fprintf(stderr, "You cannot grab yourself in OLC.\n"); |
---|
49 | status = NO_ACTION; |
---|
50 | break; |
---|
51 | |
---|
52 | case PERMISSION_DENIED: |
---|
53 | fprintf(stderr, |
---|
54 | "You cannot grab this question.\n"); |
---|
55 | status = NO_ACTION; |
---|
56 | break; |
---|
57 | |
---|
58 | case CONNECTED: |
---|
59 | fprintf(stderr, "You are connected to another user.\n"); |
---|
60 | |
---|
61 | case HAS_QUESTION: |
---|
62 | get_prompted_input("Would you like to create another instance to grab this question? " ,buf); |
---|
63 | if(string_equiv(buf,"yes",1)) |
---|
64 | return(t_grab(Request,TRUE,hold)); |
---|
65 | status = NO_ACTION; |
---|
66 | break; |
---|
67 | |
---|
68 | case SUCCESS: |
---|
69 | printf("User grabbed.\n"); |
---|
70 | status = SUCCESS; |
---|
71 | break; |
---|
72 | |
---|
73 | case ALREADY_CONNECTED: |
---|
74 | printf("Someone is already connected to %s (%d).\n", |
---|
75 | Request->target.username,Request->target.instance); |
---|
76 | status = NO_ACTION; |
---|
77 | break; |
---|
78 | |
---|
79 | case MAX_ANSWER: |
---|
80 | printf("You cannot answer any more questions simultaneously\n"); |
---|
81 | printf("without forwarding one of your existing connections.\n"); |
---|
82 | status = NO_ACTION; |
---|
83 | break; |
---|
84 | |
---|
85 | case NO_QUESTION: |
---|
86 | printf("%s (%d) does not have a question.\n",Request->target.username, |
---|
87 | Request->target.instance); |
---|
88 | status = ERROR; |
---|
89 | break; |
---|
90 | |
---|
91 | case FAILURE: |
---|
92 | case ERROR: |
---|
93 | fprintf(stderr, "Error grabbing user.\n"); |
---|
94 | status = ERROR; |
---|
95 | break; |
---|
96 | |
---|
97 | default: |
---|
98 | status = handle_response(status,Request); |
---|
99 | break; |
---|
100 | } |
---|
101 | |
---|
102 | if((instance != Request->requester.instance) && !hold) |
---|
103 | { |
---|
104 | printf("You are now %s (%d).\n",Request->requester.username, |
---|
105 | Request->requester.instance); |
---|
106 | User.instance = Request->requester.instance; |
---|
107 | } |
---|
108 | return(status); |
---|
109 | } |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | ERRCODE |
---|
115 | t_forward(Request) |
---|
116 | REQUEST *Request; |
---|
117 | |
---|
118 | { |
---|
119 | int status; |
---|
120 | int instance; |
---|
121 | |
---|
122 | instance = Request->requester.instance; |
---|
123 | status = OForward(Request); |
---|
124 | |
---|
125 | switch (status) |
---|
126 | { |
---|
127 | case SUCCESS: |
---|
128 | printf("Question forwarded. "); |
---|
129 | if(is_option(Request->options, OFF_OPT)) |
---|
130 | printf("You have signed off OLC.\n"); |
---|
131 | else |
---|
132 | printf("You are signed off OLC.\n"); |
---|
133 | |
---|
134 | t_set_default_instance(Request); |
---|
135 | status = SUCCESS; |
---|
136 | break; |
---|
137 | |
---|
138 | case CONNECTED: |
---|
139 | printf("Question forwarded. You are now connected to another user.\n"); |
---|
140 | status = SUCCESS; |
---|
141 | break; |
---|
142 | |
---|
143 | case SIGNED_OFF: |
---|
144 | printf("Question forwarded. "); |
---|
145 | if(is_option(Request->options, OFF_OPT)) |
---|
146 | printf("You have signed off OLC.\n"); |
---|
147 | else |
---|
148 | printf("You are signed off of OLC.\n"); |
---|
149 | |
---|
150 | t_set_default_instance(Request); |
---|
151 | status = SUCCESS; |
---|
152 | break; |
---|
153 | |
---|
154 | case NOT_CONNECTED: |
---|
155 | fprintf(stderr,"You have no question to forward.\n"); |
---|
156 | status = ERROR; |
---|
157 | break; |
---|
158 | |
---|
159 | case HAS_QUESTION: |
---|
160 | fprintf(stderr,"You cannot forward your own question.\n"); |
---|
161 | status = ERROR; |
---|
162 | break; |
---|
163 | |
---|
164 | case ERROR: |
---|
165 | fprintf(stderr, "Unable to forward question. Dunno why.\n"); |
---|
166 | status = ERROR; |
---|
167 | break; |
---|
168 | |
---|
169 | default: |
---|
170 | status = handle_response(status, Request); |
---|
171 | break; |
---|
172 | } |
---|
173 | |
---|
174 | if(instance != Request->requester.instance) |
---|
175 | printf("You are %s (%d), again.\n",Request->requester.username, |
---|
176 | Request->requester.instance); |
---|
177 | |
---|
178 | return(status); |
---|
179 | } |
---|
180 | |
---|