Added Difficulty rating to Sessions. Update time in real time. Fix "Loop
1".
This commit is contained in:
parent
5978cf6e49
commit
87ab40209b
BIN
sigIRCv2.jar
BIN
sigIRCv2.jar
Binary file not shown.
@ -61,6 +61,10 @@ public class Profile {
|
||||
this.parent = module;
|
||||
}
|
||||
|
||||
public Profile getArchive() {
|
||||
return oldProfile;
|
||||
}
|
||||
|
||||
public void archiveAllValues() {
|
||||
oldProfile.healthUps = healthUps;
|
||||
oldProfile.attackUps = attackUps;
|
||||
@ -70,6 +74,7 @@ public class Profile {
|
||||
oldProfile.rainbowEggCount = rainbowEggCount;
|
||||
oldProfile.key_items = (HashMap<MemoryData, Integer>)key_items.clone();
|
||||
oldProfile.badges = (HashMap<MemoryData, Integer>)badges.clone();
|
||||
oldProfile.playtime = playtime;
|
||||
}
|
||||
|
||||
public void compareAndAnnounceAllChangedValues() {
|
||||
@ -173,7 +178,7 @@ public class Profile {
|
||||
}
|
||||
}
|
||||
|
||||
public void downloadProfile() {
|
||||
public boolean downloadProfile() {
|
||||
if (sigIRC.authenticated) {
|
||||
File file = new File(sigIRC.BASEDIR+"tmp_profile");
|
||||
try {
|
||||
@ -223,8 +228,10 @@ public class Profile {
|
||||
while (!nextval.equalsIgnoreCase("UPDATES:"));
|
||||
}
|
||||
lastWebUpdate = System.currentTimeMillis();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getDataString() {
|
||||
@ -319,9 +326,9 @@ public class Profile {
|
||||
};
|
||||
String diffstring = "";
|
||||
if (difficulty<difficulty_list.length) {
|
||||
diffstring = difficulty_list[difficulty]+((loop>0)?" Loop "+loop:"");
|
||||
diffstring = difficulty_list[difficulty]+((loop>1)?" Loop "+loop:"");
|
||||
} else {
|
||||
diffstring = difficulty_list[difficulty_list.length-1]+((loop>0)?" Loop "+loop:"");
|
||||
diffstring = difficulty_list[difficulty_list.length-1]+((loop>1)?" Loop "+loop:"");
|
||||
}
|
||||
return diffstring;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ public class Session {
|
||||
String name = "";
|
||||
int maxPlayers = 0;
|
||||
String password = "";
|
||||
float difficulty = -1;
|
||||
int id = 0;
|
||||
List<Profile> players = new ArrayList<Profile>();
|
||||
|
||||
@ -32,31 +33,36 @@ public class Session {
|
||||
if (split.length>=7) {
|
||||
String val = split[i++];
|
||||
String[] playerlist = val.split(";");
|
||||
//System.out.println(Arrays.toString(playerlist));
|
||||
if (playerlist.length>0) {
|
||||
System.out.println(Arrays.toString(playerlist));
|
||||
if (playerlist.length>1) {
|
||||
for (String s : playerlist) {
|
||||
Profile p = new Profile(RabiRaceModule.module,true);
|
||||
p.username=s;
|
||||
//System.out.println("Player "+p.username);
|
||||
p.downloadProfile();
|
||||
if (p.downloadProfile()) {
|
||||
if (RabiRaceModule.mySession==null && p.username.equalsIgnoreCase(RabiRaceModule.module.myProfile.username)) {
|
||||
RabiRaceModule.mySession = this;
|
||||
}
|
||||
//System.out.println("Adding Player "+p);
|
||||
players.add(p);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Profile p = new Profile(RabiRaceModule.module,true);
|
||||
p.username=val;
|
||||
//System.out.println("Player "+p.username);
|
||||
if (p.downloadProfile()) {
|
||||
if (RabiRaceModule.mySession==null && p.username.equalsIgnoreCase(RabiRaceModule.module.myProfile.username)) {
|
||||
RabiRaceModule.mySession = this;
|
||||
}
|
||||
//System.out.println("Adding Player "+p);
|
||||
players.add(p);
|
||||
}
|
||||
} else {
|
||||
Profile p = new Profile(RabiRaceModule.module,true);
|
||||
p.username=val;
|
||||
//System.out.println("Player "+p.username);
|
||||
p.downloadProfile();
|
||||
if (RabiRaceModule.mySession==null && p.username.equalsIgnoreCase(RabiRaceModule.module.myProfile.username)) {
|
||||
RabiRaceModule.mySession = this;
|
||||
}
|
||||
//System.out.println("Adding Player "+p);
|
||||
players.add(p);
|
||||
}
|
||||
}
|
||||
if (split.length>=8) {
|
||||
difficulty = Float.parseFloat(split[i++]);
|
||||
}
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
|
@ -30,6 +30,7 @@ public class SessionCreateWindow extends JFrame{
|
||||
JPanel container = new JPanel();
|
||||
LengthValidationField session_name = new LengthValidationField(16);
|
||||
NumberValidationField maxplayers = new NumberValidationField();
|
||||
FloatValidationField difficulty = new FloatValidationField();
|
||||
JPasswordField pass = new JPasswordField();
|
||||
JButton create = new JButton("Create");
|
||||
|
||||
@ -40,9 +41,10 @@ public class SessionCreateWindow extends JFrame{
|
||||
JPanel namepanel = new JPanel();
|
||||
JPanel playerpanel = new JPanel();
|
||||
JPanel passwordpanel = new JPanel();
|
||||
JPanel difficultypanel = new JPanel();
|
||||
|
||||
JPanel[] panel_list = new JPanel[]{
|
||||
namepanel,playerpanel,passwordpanel
|
||||
namepanel,playerpanel,passwordpanel,difficultypanel
|
||||
};
|
||||
|
||||
for (JPanel panel : panel_list) {
|
||||
@ -73,6 +75,13 @@ public class SessionCreateWindow extends JFrame{
|
||||
playerpanel.add(passwordLabel);
|
||||
playerpanel.add(pass);
|
||||
|
||||
JLabel difficultyLabel = new JLabel("Race Difficulty (0.00~10.00): ");
|
||||
difficulty.setPreferredSize(new Dimension(60,24));
|
||||
difficulty.setText("5.00");
|
||||
|
||||
difficultypanel.add(difficultyLabel);
|
||||
difficultypanel.add(difficulty);
|
||||
|
||||
for (JPanel panel : panel_list) {
|
||||
panel.add(Box.createRigidArea(new Dimension(24,24)));
|
||||
}
|
||||
@ -102,6 +111,10 @@ public class SessionCreateWindow extends JFrame{
|
||||
JOptionPane.showMessageDialog(RabiRaceModule.createwindow, "Your max player count needs to be between 2-48!", "Error!", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
if (!TextUtils.isNumeric(difficulty.getText()) && difficulty.getText().length()>0) {
|
||||
JOptionPane.showMessageDialog(RabiRaceModule.createwindow, "Your difficulty value is invalid! (A number between 0.00 and 10.00)", "Error!", JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
}
|
||||
String hashpass = "";
|
||||
if (String.copyValueOf(pass.getPassword()).length()>0) {
|
||||
hashpass = SessionListWindow.GetHashedPassword(String.copyValueOf(pass.getPassword()));
|
||||
@ -109,7 +122,8 @@ public class SessionCreateWindow extends JFrame{
|
||||
session_name.setText(session_name.getText().replaceAll(" ", "%20"));
|
||||
File file = new File(sigIRC.BASEDIR+"sigIRC/tmp.data");
|
||||
try {
|
||||
org.apache.commons.io.FileUtils.copyURLToFile(new URL("http://45.33.13.215/rabirace/send.php?key=sessioncreate&name="+session_name.getText()+"&players="+maxplayers.getText()+"&password="+((hashpass.length()>0)?hashpass:"none")),file);
|
||||
org.apache.commons.io.FileUtils.copyURLToFile(new URL("http://45.33.13.215/rabirace/send.php?key=sessioncreate&name="+session_name.getText()+"&players="+maxplayers.getText()+"&password="+((hashpass.length()>0)?hashpass:"none")+"&difficulty="+((difficulty.getText().length()>0)?difficulty.getText():"-1")),file);
|
||||
//org.apache.commons.io.FileUtils.copyURLToFile(new URL("http://45.33.13.215/rabirace/send.php?key=sessioncreate&name="+session_name.getText()+"&players="+maxplayers.getText()+"&password="+((hashpass.length()>0)?hashpass:"none")),file);
|
||||
String[] contents = FileUtils.readFromFile(sigIRC.BASEDIR+"sigIRC/tmp.data");
|
||||
int sessionID=-1;
|
||||
if (contents.length>=2) {
|
||||
@ -139,6 +153,7 @@ public class SessionCreateWindow extends JFrame{
|
||||
container.add(namepanel);
|
||||
container.add(playerpanel);
|
||||
container.add(passwordpanel);
|
||||
container.add(difficultypanel);
|
||||
container.add(create);
|
||||
container.add(Box.createRigidArea(new Dimension(24,24)));
|
||||
|
||||
@ -223,4 +238,46 @@ public class SessionCreateWindow extends JFrame{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class FloatValidationField extends JTextField implements DocumentListener{
|
||||
|
||||
public FloatValidationField() {
|
||||
getDocument().addDocumentListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent arg0) {
|
||||
ValidateForm();
|
||||
}
|
||||
|
||||
protected void ValidateForm() {
|
||||
if (fieldIsInvalid()) {
|
||||
setBackground(Color.RED);
|
||||
} else {
|
||||
setBackground(Color.WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent arg0) {
|
||||
ValidateForm();
|
||||
}
|
||||
|
||||
protected boolean fieldIsInvalid() {
|
||||
if (!TextUtils.isNumeric(getText()) && getText().length()>0) {
|
||||
return true;
|
||||
}
|
||||
if (TextUtils.isNumeric(getText()) && getText().length()>0) {
|
||||
float val = Float.parseFloat(getText());
|
||||
if (val>10f || val<0f) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -43,6 +44,7 @@ public class SessionListWindow extends JFrame{
|
||||
public JScrollPane scrolllist = new JScrollPane();
|
||||
public PasswordBox box = new PasswordBox();
|
||||
public String enteredPassword = "";
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
|
||||
|
||||
public SessionListWindow(){
|
||||
@ -52,8 +54,8 @@ public class SessionListWindow extends JFrame{
|
||||
previewPanel.setWindow(this);
|
||||
|
||||
scrolllist.setViewportView(sessionlist);
|
||||
scrolllist.setPreferredSize(new Dimension(160,150));
|
||||
scrolllist.setMinimumSize(new Dimension(160,150));
|
||||
scrolllist.setPreferredSize(new Dimension(272,150));
|
||||
scrolllist.setMinimumSize(new Dimension(272,150));
|
||||
scrolllist.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
JPanel sessionPanel = new JPanel();
|
||||
|
||||
@ -137,7 +139,7 @@ public class SessionListWindow extends JFrame{
|
||||
|
||||
|
||||
this.add(container);
|
||||
this.setMinimumSize(new Dimension(640,480));
|
||||
this.setMinimumSize(new Dimension(720,480));
|
||||
}
|
||||
|
||||
public static void ConnectToSession(Session session, String hashedPass) {
|
||||
@ -200,7 +202,7 @@ public class SessionListWindow extends JFrame{
|
||||
int count=0;
|
||||
for (Integer id : RabiRaceModule.module.session_listing.data.keySet()) {
|
||||
Session session = RabiRaceModule.module.session_listing.data.get(id);
|
||||
sessionlist_model.addElement((session.password.equalsIgnoreCase("none")?"":"🔑 ")+session.id+" - "+session.name+" ("+session.players.size()+"/"+session.maxPlayers+")");
|
||||
sessionlist_model.addElement((session.password.equalsIgnoreCase("none")?"":"🔑 ")+session.id+" - "+session.name+" ("+session.players.size()+"/"+session.maxPlayers+")"+((session.difficulty!=-1)?" - Rating: "+df.format(session.difficulty):""));
|
||||
if (id == selectedID && sessionlist_model.getSize()>count) {
|
||||
sessionlist.setSelectedIndex(count);
|
||||
}
|
||||
|
@ -295,6 +295,13 @@ public class RabiRaceModule extends Module{
|
||||
}
|
||||
firstUpdate=false;
|
||||
}
|
||||
for (Profile p : mySession.getPlayers()) {
|
||||
if (!p.username.equalsIgnoreCase(myProfile.username)) {
|
||||
if (!p.isPaused) {
|
||||
p.playtime += myProfile.playtime-myProfile.getArchive().playtime;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user