90 lines
3.1 KiB
C#
90 lines
3.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace MrAG
|
|
{
|
|
public class Leaderboard
|
|
{
|
|
public class GamerServicesLeaderboardException : Exception{
|
|
public GamerServicesLeaderboardException(string msg): base(msg){
|
|
}
|
|
}
|
|
|
|
public static Entry SubmittedEntry;
|
|
|
|
public class Entry{
|
|
public string Username;
|
|
public string Board;
|
|
public int Score;
|
|
public int Rank;
|
|
|
|
public Entry(string user, int pos, int score){
|
|
Rank = pos;
|
|
Score = score;
|
|
Username = user;
|
|
}
|
|
|
|
public Entry(string user, string board, int pos, int score){
|
|
Board = board;
|
|
Rank = pos;
|
|
Score = score;
|
|
Username = user;
|
|
}
|
|
}
|
|
|
|
public static void Submit(string board, int score){
|
|
SubmittedEntry = new Entry(MrAG.Gamerservices.GetUser(), board, -1, score);
|
|
Gamerservices.GetAPIConnection().Send(3, 9 + board.Length, (byte)1, board, score);
|
|
}
|
|
|
|
public static List<Entry> GetList(string board, int startpos, int length){
|
|
throw new GamerServicesLeaderboardException("NOT SUPPORTED");
|
|
|
|
/*
|
|
try{
|
|
string[] list = Networking.PostData("leaderboard", "sub=list&identifier=" + board +"&start=" + startpos + "&length=" + length);
|
|
|
|
List<Entry> entrys = new List<Entry>();
|
|
for (int i = 0; i < list.Length; i++){
|
|
entrys.Add(new Entry(list[i], int.Parse(list[i + 1]), int.Parse(list[i + 2])));
|
|
|
|
i += 2;
|
|
}
|
|
|
|
return entrys;
|
|
}catch{
|
|
throw new GamerServicesLeaderboardException("Error while recieving list");
|
|
}*/
|
|
}
|
|
|
|
public static Entry GetUser(string board, string user){
|
|
Networking.TCPClient c = Gamerservices.GetAPIConnection();
|
|
c.Connection.Start_Recieve(); // just to make sure we are free to recieve the incomming data
|
|
c.Connection.Send(3, 9 + board.Length + user.Length, (byte)1, board, user);
|
|
|
|
int pos = c.Connection.ReadInt();
|
|
int score = c.Connection.ReadInt();
|
|
c.Connection.Finish_Recieve();
|
|
return new Entry(MrAG.Gamerservices.GetUser(), pos, score);
|
|
|
|
/*
|
|
string[] list = Networking.PostData("leaderboard", "sub=get&identifier=" + board +"&user=" + user);
|
|
|
|
if (list.Length == 0 || list[0].Length == 0) return new List<Entry>(){new Entry(user, -1, -1)};
|
|
|
|
try{
|
|
List<Entry> entrys = new List<Entry>();
|
|
for (int i = 0; i < list.Length; i++){
|
|
entrys.Add(new Entry(user, int.Parse(list[i]), int.Parse(list[i + 1])));
|
|
|
|
i++;
|
|
}
|
|
|
|
return entrys;
|
|
}catch{
|
|
throw new GamerServicesLeaderboardException("Error while reading data");
|
|
}*/
|
|
}
|
|
}
|
|
}
|