[Freeciv-Dev] (PR#15923) can_conn_edit
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=15923 >
This patch adds 2 query functions for editing. can_conn_edit returns
true if the connection is allowed to edit. can_conn_enable_editing
returns true if the connection is allowed to enable editing. Simple enough.
The functions are put in connection.[ch]. I don't think this is the
right place but there is nowhere better for them.
They are used in server and client. I made a couple of minor fixes in
the nation-select-req packet and the client menu code.
-jason
Index: server/srv_main.c
===================================================================
--- server/srv_main.c (revision 11774)
+++ server/srv_main.c (working copy)
@@ -1029,6 +1029,7 @@
/* valid packets from established connections but non-players */
if (type == PACKET_CHAT_MSG_REQ
|| type == PACKET_SINGLE_WANT_HACK_REQ
+ || type == PACKET_NATION_SELECT_REQ
|| type == PACKET_EDIT_MODE
|| type == PACKET_EDIT_TILE
|| type == PACKET_EDIT_UNIT
@@ -1271,7 +1272,7 @@
/**************************************************************************
...
**************************************************************************/
-void handle_nation_select_req(struct player *requestor,
+void handle_nation_select_req(struct connection *pc,
int player_no,
Nation_type_id nation_no, bool is_male,
char *name, int city_style)
@@ -1279,16 +1280,10 @@
struct nation_type *old_nation, *new_nation;
struct player *pplayer = get_player(player_no);
- if (!(requestor->current_conn->access_level == ALLOW_HACK
- && game.info.is_edit_mode)
- && (server_state != PRE_GAME_STATE || !pplayer)) {
+ if (!pplayer || !can_conn_edit_players_nation(pc, pplayer)) {
return;
}
- if (!can_conn_edit_players_nation(requestor->current_conn, pplayer)) {
- return;
- }
-
old_nation = pplayer->nation;
new_nation = get_nation_by_idx(nation_no);
Index: server/edithand.c
===================================================================
--- server/edithand.c (revision 11774)
+++ server/edithand.c (working copy)
@@ -43,7 +43,7 @@
****************************************************************************/
void handle_edit_mode(struct connection *pc, bool is_edit_mode)
{
- if (pc->access_level != ALLOW_HACK) {
+ if (!can_conn_enable_editing(pc)) {
return;
}
if (!game.info.is_edit_mode && is_edit_mode) {
@@ -75,8 +75,7 @@
struct terrain *pterrain = get_terrain(terrain), *old_terrain;
struct resource *presource = get_resource(resource);
- if (pc->access_level != ALLOW_HACK || !game.info.is_edit_mode
- || !ptile || !pterrain) {
+ if (!can_conn_edit(pc) || !ptile || !pterrain) {
return;
}
@@ -114,7 +113,7 @@
struct player *pplayer = get_player(packet->owner);
struct unit *punit;
- if (pc->access_level != ALLOW_HACK || !game.info.is_edit_mode
+ if (!can_conn_edit(pc)
|| !ptile || !punittype || !pplayer
|| (packet->create_new && packet->delete)) {
return;
@@ -186,8 +185,8 @@
struct tile *ptile = map_pos_to_tile(x, y);
struct city *pcity;
struct player *pplayer = get_player(owner);
- if (pc->access_level != ALLOW_HACK || !game.info.is_edit_mode
- || !pplayer || !ptile) {
+
+ if (!can_conn_edit(pc) || !pplayer || !ptile) {
return;
}
@@ -224,8 +223,7 @@
int i;
int old_traderoutes[NUM_TRADEROUTES];
- if (pc->access_level != ALLOW_HACK || !game.info.is_edit_mode
- || !pplayer || !ptile) {
+ if (!can_conn_edit(pc) || !pplayer || !ptile) {
return;
}
@@ -310,8 +308,7 @@
{
struct city *pcity = find_city_by_id(id);
- if (pc->access_level != ALLOW_HACK || !game.info.is_edit_mode
- || !pcity) {
+ if (!can_conn_edit(pc) || !pcity) {
return;
}
@@ -341,7 +338,7 @@
#endif
/* FIXME: Are NULL teams allowed? */
- if (pc->access_level != ALLOW_HACK || !game.info.is_edit_mode
+ if (!can_conn_edit(pc)
|| !pplayer || !pnation || !pteam || !pgov) {
return;
}
@@ -413,7 +410,7 @@
****************************************************************************/
void handle_edit_recalculate_borders(struct connection *pc)
{
- if (game.info.is_edit_mode) {
+ if (can_conn_edit(pc)) {
map_calculate_borders();
}
}
Index: common/packets.def
===================================================================
--- common/packets.def (revision 11774)
+++ common/packets.def (working copy)
@@ -296,7 +296,7 @@
PACKET_SERVER_SHUTDOWN=8;sc,lsend
end
-PACKET_NATION_SELECT_REQ=10;cs,dsend
+PACKET_NATION_SELECT_REQ=10;cs,handle-per-conn,dsend
PLAYER player_no;
NATION nation_no;
BOOL is_male;
Index: common/connection.c
===================================================================
--- common/connection.c (revision 11774)
+++ common/connection.c (working copy)
@@ -530,6 +530,22 @@
return buffer;
}
+/****************************************************************************
+ Return TRUE iff the connection is currently allowed to edit.
+****************************************************************************/
+bool can_conn_edit(const struct connection *pconn)
+{
+ return can_conn_enable_editing(pconn) && game.info.is_edit_mode;
+}
+
+/****************************************************************************
+ Return TRUE iff the connection is allowed to start editing.
+****************************************************************************/
+bool can_conn_enable_editing(const struct connection *pconn)
+{
+ return pconn->access_level == ALLOW_HACK;
+}
+
/**************************************************************************
Get next request id. Takes wrapping of the 16 bit wide unsigned int
into account.
Index: common/connection.h
===================================================================
--- common/connection.h (revision 11774)
+++ common/connection.h (working copy)
@@ -269,6 +269,9 @@
const char *conn_description(const struct connection *pconn);
+bool can_conn_edit(const struct connection *pconn);
+bool can_conn_enable_editing(const struct connection *pconn);
+
int get_next_request_id(int old_request_id);
extern const char blank_addr_str[];
Index: common/nation.c
===================================================================
--- common/nation.c (revision 11774)
+++ common/nation.c (working copy)
@@ -396,7 +396,7 @@
bool can_conn_edit_players_nation(const struct connection *pconn,
const struct player *pplayer)
{
- return ((pconn->access_level == ALLOW_HACK && game.info.is_edit_mode)
+ return (can_conn_edit(pconn)
|| (game.info.is_new_game
&& ((!pconn->observer && pconn->player == pplayer)
|| pconn->access_level >= ALLOW_CTRL)));
Index: client/gui-gtk-2.0/citydlg.c
===================================================================
--- client/gui-gtk-2.0/citydlg.c (revision 11774)
+++ client/gui-gtk-2.0/citydlg.c (working copy)
@@ -1362,7 +1362,7 @@
get_city_citizen_types(pcity, 4, citizens);
i = 0;
- if (game.info.is_edit_mode) {
+ if (can_conn_edit(&aconnection)) {
gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
get_arrow_sprite(tileset, ARROW_PLUS),
i++ * width, 0);
@@ -2348,7 +2348,7 @@
tlen = tileset_small_sprite_width(tileset);
len = (pcity->size - 1) * pdialog->cwidth + tlen;
- if (game.info.is_edit_mode) {
+ if (can_conn_edit(&aconnection)) {
if (ev->x > 0 && ev->x <= tlen) {
dsend_packet_edit_city_size(&aconnection, pcity->id, pcity->size + 1);
return TRUE;
Index: client/gui-gtk-2.0/menu.c
===================================================================
--- client/gui-gtk-2.0/menu.c (revision 11774)
+++ client/gui-gtk-2.0/menu.c (working copy)
@@ -938,7 +938,7 @@
/* Editor menu */
{ "/" N_("_Editor"), NULL, NULL, 0, "<Branch>" },
{ "/" N_("_Editor") "/tearoff1", NULL, NULL, 0, "<Tearoff>" },
- { "/" N_("_Editor") "/" N_("Editing Mode"), NULL,
+ { "/" N_("_Editor") "/" N_("_Editing Mode"), NULL,
editor_menu_callback, MENU_EDITOR_TOGGLE, "<CheckItem>" },
{ "/" N_("_Editor") "/" N_("_Tools"), NULL,
editor_menu_callback, MENU_EDITOR_TOOLS },
@@ -1337,11 +1337,14 @@
menus_set_active("<main>/_View/_Full Screen", fullscreen_mode);
- menus_set_sensitive("<main>/_Editor", TRUE);
- menus_set_sensitive("<main>/_Editor/_Tools", game.info.is_edit_mode);
+ menus_set_sensitive("<main>/_Editor",
+ can_conn_enable_editing(&aconnection));
+ menus_set_sensitive("<main>/_Editor/_Tools",
+ can_conn_edit(&aconnection));
menus_set_sensitive("<main>/_Editor/_Recalculate Borders",
- game.info.is_edit_mode);
- menus_set_active("<main>/_Editor/Editing Mode", game.info.is_edit_mode);
+ can_conn_edit(&aconnection));
+ menus_set_active("<main>/_Editor/Editing Mode",
+ can_conn_edit(&aconnection));
/* Remaining part of this function: Update Orders menu */
Index: client/gui-gtk-2.0/dialogs.c
===================================================================
--- client/gui-gtk-2.0/dialogs.c (revision 11774)
+++ client/gui-gtk-2.0/dialogs.c (working copy)
@@ -760,8 +760,7 @@
int i;
char *title;
- if (game.info.is_edit_mode
- && get_client_state() == CLIENT_GAME_RUNNING_STATE) {
+ if (get_client_state() == CLIENT_GAME_RUNNING_STATE) {
title = _("Edit Nation");
} else if (pplayer && pplayer == game.player_ptr) {
title = _("What Nation Will You Be?");
Index: client/gui-gtk-2.0/plrdlg.c
===================================================================
--- client/gui-gtk-2.0/plrdlg.c (revision 11774)
+++ client/gui-gtk-2.0/plrdlg.c (working copy)
@@ -516,7 +516,7 @@
players_edit_menu = gtk_menu_item_new_with_mnemonic(_("_Editor"));
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), players_edit_menu);
- gtk_widget_set_sensitive(players_edit_menu, game.info.is_edit_mode);
+ gtk_widget_set_sensitive(players_edit_menu, can_conn_edit(&aconnection));
menu = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(players_edit_menu), menu);
@@ -726,7 +726,7 @@
} players_iterate_end;
/* menu needs to be updated with edit mode changes */
- gtk_widget_set_sensitive(players_edit_menu, game.info.is_edit_mode);
+ gtk_widget_set_sensitive(players_edit_menu, can_conn_edit(&aconnection));
update_players_menu();
update_views();
Index: client/mapctrl_common.c
===================================================================
--- client/mapctrl_common.c (revision 11774)
+++ client/mapctrl_common.c (working copy)
@@ -531,7 +531,7 @@
{
struct tile *ptile = canvas_pos_to_tile(canvas_x, canvas_y);
- if (!ptile->city && game.info.is_edit_mode) {
+ if (!ptile->city && can_conn_edit(&aconnection)) {
editor_do_click(ptile);
} else if (can_client_change_view() && ptile) {
/* FIXME: Some actions here will need to check can_client_issue_orders.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#15923) can_conn_edit,
Jason Short <=
|
|