[Freeciv-Dev] (PR#13149) allow changing of other players' nations
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: |
[Freeciv-Dev] (PR#13149) allow changing of other players' nations |
From: |
"Jason Dorje Short" <jdorje@xxxxxxxxx> |
Date: |
Fri, 20 May 2005 08:43:57 -0700 |
Reply-to: |
bugs@xxxxxxxxxxx |
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13149 >
This patch does all of the work that should be needed to let you edit
other players nations.
- The nation-req packet takes a player #. Those with ctrl access can
change other players' nations.
- Clicking on the nation of a player in the pregame players dialog pops
up the nation dialog for that player. Only one nation dialog can be up
at a time.
The latter exposes a bug in the client-server connection.
game.info.nplayers is 0 so find_player_by_user doesn't work. Instead I
just used find_conn_by_user()->player.
Also note that only connections are shown in the list, not players. So
you can only change the nation of another human player. This is
obviously a bug of course.
-jason
Index: client/gui-gtk-2.0/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/dialogs.c,v
retrieving revision 1.104
diff -u -r1.104 dialogs.c
--- client/gui-gtk-2.0/dialogs.c 5 May 2005 19:22:24 -0000 1.104
+++ client/gui-gtk-2.0/dialogs.c 20 May 2005 15:43:35 -0000
@@ -65,6 +65,7 @@
/******************************************************************/
static GtkWidget *races_shell;
+struct player *races_player;
static GtkWidget *races_nation_list[MAX_NUM_NATION_GROUPS + 1];
static GtkWidget *races_leader;
static GList *races_leader_list;
@@ -92,7 +93,7 @@
static void select_random_race(void);
-static void create_races_dialog(void);
+static void create_races_dialog(struct player *pplayer);
static void races_destroy_callback(GtkWidget *w, gpointer data);
static void races_response(GtkWidget *w, gint response, gpointer data);
static void races_nation_callback(GtkTreeSelection *select, gpointer data);
@@ -1668,7 +1669,7 @@
/****************************************************************
...
*****************************************************************/
-static void create_races_dialog(void)
+static void create_races_dialog(struct player *pplayer)
{
GtkWidget *shell;
GtkWidget *cmd;
@@ -1697,6 +1698,7 @@
GTK_RESPONSE_ACCEPT,
NULL);
races_shell = shell;
+ races_player = pplayer;
setup_dialog(shell, toplevel);
gtk_window_set_position(GTK_WINDOW(shell), GTK_WIN_POS_CENTER_ON_PARENT);
@@ -1860,12 +1862,14 @@
/****************************************************************
popup the dialog 10% inside the main-window
*****************************************************************/
-void popup_races_dialog(void)
+void popup_races_dialog(struct player *pplayer)
{
- create_races_dialog();
- gtk_window_present(GTK_WINDOW(races_shell));
+ if (!races_shell) {
+ create_races_dialog(pplayer);
+ gtk_window_present(GTK_WINDOW(races_shell));
- select_random_race();
+ select_random_race();
+ }
}
/****************************************************************
@@ -2205,10 +2209,13 @@
return;
}
- dsend_packet_nation_select_req(&aconnection, selected_nation,
+ dsend_packet_nation_select_req(&aconnection,
+ races_player->player_no, selected_nation,
selected_sex, s, selected_city_style);
} else if (response == GTK_RESPONSE_CANCEL) {
- dsend_packet_nation_select_req(&aconnection, NO_NATION_SELECTED,
+ dsend_packet_nation_select_req(&aconnection,
+ races_player->player_no,
+ NO_NATION_SELECTED,
FALSE, "", 0);
}
popdown_races_dialog();
Index: client/gui-gtk-2.0/pages.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/pages.c,v
retrieving revision 1.28
diff -u -r1.28 pages.c
--- client/gui-gtk-2.0/pages.c 5 May 2005 19:22:24 -0000 1.28
+++ client/gui-gtk-2.0/pages.c 20 May 2005 15:43:37 -0000
@@ -47,7 +47,9 @@
#include "plrdlg.h" /* for get_flag() */
GtkWidget *start_message_area;
-GtkListStore *conn_model;
+
+GtkListStore *conn_model;
+GtkTreeViewColumn *nation_col;
static GtkWidget *start_options_table;
@@ -934,7 +936,7 @@
**************************************************************************/
static void pick_nation_callback(GtkWidget *w, gpointer data)
{
- popup_races_dialog();
+ popup_races_dialog(game.player_ptr);
}
/**************************************************************************
@@ -946,6 +948,46 @@
gtk_spin_button_set_value(GTK_SPIN_BUTTON(start_aifill_spin), 5);
}
+static gboolean playerlist_event(GtkWidget *widget, GdkEventButton *event,
+ gpointer data)
+{
+ GtkTreeView *tree = GTK_TREE_VIEW(widget);
+ GtkTreeModel *model = gtk_tree_view_get_model(tree);
+ GtkTreeIter iter;
+ GtkTreePath *path = NULL;
+ GtkTreeViewColumn *column = NULL;
+ char *username;
+ struct player *pplayer;
+
+ if (event->type != GDK_BUTTON_PRESS
+ || !gtk_tree_view_get_path_at_pos(tree,
+ event->x, event->y,
+ &path, &column, NULL, NULL)) {
+ return FALSE;
+ }
+
+ if (column != nation_col) {
+ return show_conn_popup(widget, event, data);
+ }
+
+ gtk_tree_model_get_iter(model, &iter, path);
+ gtk_tree_path_free(path);
+ gtk_tree_model_get(model, &iter, 0, &username, -1);
+#if 0
+ /* This doesn't work because game.info.nplayers is 0 for some reason. */
+ pplayer = find_player_by_user(username);
+#else
+ pplayer = find_conn_by_user(username)->player;
+#endif
+ if (!pplayer) {
+ freelog(LOG_NORMAL, "No player for '%s'.", username);
+ return FALSE;
+ }
+
+ popup_races_dialog(pplayer);
+ return TRUE;
+}
+
/**************************************************************************
create start page.
**************************************************************************/
@@ -1069,12 +1111,13 @@
"text", 2, NULL);
rend = gtk_cell_renderer_text_new();
- gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view),
- -1, _("Nation"), rend,
- "text", 3, NULL);
+ nation_col = gtk_tree_view_column_new_with_attributes(_("Nation"),
+ rend,
+ "text", 3, NULL);
+ gtk_tree_view_insert_column(GTK_TREE_VIEW(view), nation_col, -1);
g_signal_connect(view, "button-press-event",
- G_CALLBACK(show_conn_popup), NULL);
+ G_CALLBACK(playerlist_event), NULL);
sw = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
Index: client/include/dialogs_g.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/include/dialogs_g.h,v
retrieving revision 1.24
diff -u -r1.24 dialogs_g.h
--- client/include/dialogs_g.h 5 May 2005 19:22:24 -0000 1.24
+++ client/include/dialogs_g.h 20 May 2005 15:43:37 -0000
@@ -26,7 +26,7 @@
void popup_notify_dialog(const char *caption, const char *headline,
const char *lines);
-void popup_races_dialog(void);
+void popup_races_dialog(struct player *pplayer);
void popdown_races_dialog(void);
void popup_unit_select_dialog(struct tile *ptile);
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.125
diff -u -r1.125 packets.def
--- common/packets.def 11 May 2005 20:03:08 -0000 1.125
+++ common/packets.def 20 May 2005 15:43:37 -0000
@@ -288,6 +288,7 @@
end
PACKET_NATION_SELECT_REQ=10;cs,dsend
+ PLAYER player_no;
NATION nation_no;
BOOL is_male;
STRING name[MAX_LEN_NAME];
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.261
diff -u -r1.261 srv_main.c
--- server/srv_main.c 19 May 2005 16:57:30 -0000 1.261
+++ server/srv_main.c 20 May 2005 15:43:37 -0000
@@ -1217,17 +1217,26 @@
/**************************************************************************
...
**************************************************************************/
-void handle_nation_select_req(struct player *pplayer,
+void handle_nation_select_req(struct player *requestor,
+ int player_no,
Nation_type_id nation_no, bool is_male,
char *name, int city_style)
{
- const Nation_type_id old_nation_no = pplayer->nation;
+ Nation_type_id old_nation_no;
+ struct player *pplayer = get_player(player_no);
- if (server_state != PRE_GAME_STATE) {
- freelog(LOG_ERROR, _("Trying to alloc nation outside of pregame!"));
+ if (server_state != PRE_GAME_STATE
+ || !pplayer) {
return;
}
+ if (pplayer != requestor
+ && requestor->current_conn->access_level <= ALLOW_INFO) {
+ return;
+ }
+
+ old_nation_no = pplayer->nation;
+
if (nation_no != NO_NATION_SELECTED) {
char message[1024];
struct nation_type *nation;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#13149) allow changing of other players' nations,
Jason Dorje Short <=
|
|