ID:2405289
 
Code:
atom/Topic(href,href_list[])

switch(href_list["action"])

if("rep_edit")

usr << "DEBUG: Rep Edit"

var/uname = href_list["uname"]

usr << "DEBUG: uname set!"

var/ustats = world.GetScores(uname, "Report")

usr << "DEBUG: ustats set!"

var/list/params = params2list(ustats)

usr << "DEBUG: params set!"

var/variable = params[params[1]]

usr << "DEBUG: variable set!"

if(!uname) return
if(!variable) return

variable = input("Update/Remove the Report","Player Report: [uname]",variable) as null|message
if(isnull(variable)) return

usr << "DEBUG: input complete!"

world.SetScores("[uname]","Report=[variable]")

usr << "DEBUG: world.SetScores complete!"

view_rep()

usr << "DEBUG: view_rep executed!"


Problem description:

So I'm having an issue with some code here that I'm trying out for some experimentation with use of the hub scores.

What I'm doing is using a hidden hub score to store a player message. I'm using it to allow players to submit errors/bugs/requests to me in-game without logging in on my forum. It's stored in their hidden "Report" score on the hub.

The code has been working like I wanted it to, but then I ran in to a player that started giving me some issues. I started getting this error whenever I tried to work with this player's report...


runtime error: list index out of bounds
proc name: Topic (/atom/Topic)
usr: (src)
src: IceFire2050 (/mob)
src.loc: (63,129,1) (/turf/FLOOR/CENTER)
call stack:
IceFire2050 (/mob): Topic("src=\[0x3000014];action=rep_ed...", /list (/list))
IceFire2050 (/mob): Topic("src=\[0x3000014];action=rep_ed...", /list (/list))
IceFire2050 (/client): Topic("src=\[0x3000014];action=rep_ed...", /list (/list), IceFire2050 (/mob))


After some experimenting with the issue, adding some debug lines to figure out where it's causing the error, etc I figured out 2 things.

1. This line is causing the error...
var/variable = params[params[1]]

I know this because I don't get the debug output following that line.


2. This error only occurs when a player has a space in their key. It took me a while to realize this but I've since tested it with other players and it's only then that I get the issue.


This is code used to manipulate the reports but it's accessed via a hyperlink generated on a table in another piece of code.

proc/view_rep()

var/LOG = {"<STYLE TYPE="text/css"><!--
BODY {margin: 0; padding: 8; background-color: #0c1e3a}
.vtext {font-size: 12px; font-family: Tahoma, Geneva, sans-serif ; color: white }
.vtitle {font-size: 12px; font-family: Tahoma, Geneva, sans-serif; font-weight: bold ; color: white }
a { color: #FFFFFF; }
--></STYLE><head><title>Player Reports</title></head>

<table border="1" bordercolor="#75787a" style="background-color:#515354" width="100%" cellpadding="3" cellspacing="3">

<tr>
<td width="10%" bordercolor="#3a565b" bgcolor="#2a61ba"><span class="vtitle">User</span></td>
<td width="90%" bordercolor="#3a565b" bgcolor="#2a61ba"><span class="vtitle">Report</span></td>
</tr>"}


var/ustats = world.GetScores(5000, "Report")

var/list/params = params2list(ustats)

var/i = 0
while(i < params.len)
i++

var/username = params[i]

LOG += "<tr>"
LOG += {"<td width="10%" bgcolor="#547d84"><a href=byond://?src=\ref[usr];action=rep_edit;uname=[username]>[username]</a></span></td>"}
LOG += {"<td width="90%" bgcolor="#547d84"><span class="vtext">[params[username]]</span></td>"}
LOG += "</tr>"

LOG += "</table>"

usr << browse(LOG,"window=LOG;size=705x675;border=0;can_close=1;can_resize=1;can_minimize=1;titlebar=1")

return

This checks for all players with a report value on the hub, populates a table with their key and their report. their key is a hyperlink that opens the interface to edit or delete their report if needed.

But something gets messed up somewhere along the line when it's a player with a space in their key. Anyone have any idea what's going on?
Easy fix, use ckey instead of key, or ckey() to strip the bad stuff from the value. You can also url_encode/decode things if you need the space, but you shouldn't.

In general, it's usually best to work with ckey values when it comes to things like this (and file paths) because spaces tend to muck things up unless properly stripped or encoded.
It's not pulling the key off of the player though, it's pulling it from the hub so where would the ckey come from?
From a glance your username variable would be a good place to start, the issue is likely your uname being passed gets cut off at the space, which means the index for that name doesn't exist ("John Smith" becomes "John", using ckey() would turn "John Smith" into "johnsmith")

Of course you can also replace the space with a "%20" and swap it back out on the other end, since you likely stored the value using the space.

It's all down to your link formatting though, you just need to handle the space better, when you use ckey()'d values from the beginning you don't have to worry about spaces or special characters.