|
You last visited: Today at 22:25
Advertisement
[Private Server] ICOn8 Project
Discussion on [Private Server] ICOn8 Project within the DarkOrbit forum part of the Browsergames category.
07/19/2013, 02:37
|
#841
|
elite*gold: 0
Join Date: Aug 2010
Posts: 117
Received Thanks: 72
|
Quote:
Exception in thread "main" java.lang.NullPointerException
at game.objetos.Inventario.<init>(Inventario.java:18)
at game.Usuarios.<init>(Usuarios.java:182)
at common.SQLManager.CARGAR_USUARIOS(SQLManager.java: 174)
at common.World.createWorld(World.java:96)
at common.DarkOrbit.main(DarkOrbit.java:102)
|
im getting this error too..
I decomplied all the .class files.. if you can tell me where variables go null/ sorry don't know any java programming :P
Code:
package game.objetos;
import game.Usuarios;
import java.util.ArrayList;
import utils.Logs;
public class Inventario
{
private Usuarios user;
private ArrayList<Objeto> objetos = new ArrayList();
private String minerales = "";
public Inventario(Usuarios user) {
this.user = user;
for (String objeto : user.get_inventario().split("\\|"))
{
if (!objeto.equals(""))
switch (objeto.charAt(0))
{
case 'R':
switch (objeto.charAt(1))
{
case 'M':
for (String nobj : objeto.substring(2).split("\\;"))
{
int id = 0;
int max = 0;
try
{
id = Integer.parseInt(nobj.split(",")[0]);
max = Integer.parseInt(nobj.split(",")[1]);
} catch (NumberFormatException e) { continue; }
Logs.info("Objeto cargado: RECURSO_MINERAL (" + id + ") tiene " + max + ".");
Objeto.Recurso.Mineral mineral = new Objeto.Recurso.Mineral(id, max);
Objeto.Recurso recurso = new Objeto.Recurso(mineral);
Objeto obj = new Objeto(recurso);
this.objetos.add(obj);
}
}
break;
}
}
}
public ArrayList<Objeto> getObjetos()
{
return this.objetos;
}
public Usuarios getUser() {
return this.user;
}
public void setUser(Usuarios user) {
this.user = user;
}
public String getMinerales()
{
return this.minerales;
}
public void setMinerales(String minerales) {
this.minerales = minerales;
}
}
Code:
package game;
import common.SQLManager;
import common.ServerCommands;
import common.World;
import game.objetos.Inventario;
import java.util.Map;
import java.util.TreeMap;
import javax.swing.Timer;
import net.GameThread;
import net.SocketManager;
import net.chat.ChatThread;
public class Usuarios
{
private int id;
private String usuario;
private String password;
private String email;
private int servidor;
private String fecha_nacimiento;
private String pais;
private String empresa;
private int premium;
private String fecha_creacion;
private long experiencia;
private int nivel;
private double jackpot;
private long creditos;
private long uridium;
private int energia_extra;
private int nave;
private int gfx;
private String vants;
private int skylab;
private int tecnofabrica;
private String ciudad;
private int edad;
private int sexo;
private String intereses;
private String mensaje_estado;
private int ficheros;
private int pi;
private int habilidades;
private int clan;
private int estado;
private int acceso;
private int rango;
private long honor;
private int bono_reparacion;
private int bono_teleportacion;
private int llaves;
private int puertas_alfa;
private int puertas_beta;
private int puertas_delta;
private int puertas_omega;
private int mapa;
private String pos;
private long hp;
private long hpMax;
private long escudo;
private long escudoMax;
private int vel;
private long carga;
private long cargaMax;
private String _inventario;
private Inventario inventario;
private String slot2;
private String slot3;
private String slot4;
private String mun1;
private String mun2;
private String mun3;
private int invisible;
private String titulo;
private String lastIP;
private String ultimaConexion;
private Usuarios _cuenta;
private GameThread _gameThread;
private ChatThread _chatThread;
private Usuarios _actualUsuario;
private String _actualIP = "";
private Map<Integer, Usuarios> _user = new TreeMap();
private static Map<Integer, Usuarios> conectados = new TreeMap();
private boolean _isOnline = false;
public static boolean isKilled;
public static int factionID = 0;
private String sessionID = null;
private int oldPosX = 0;
private int oldPosY = 0;
private Usuarios.Settings userSetting;
private Ship ship;
protected long _lastPacketTime;
public int tPortal = 0;
public boolean usaPortal = false;
public int tAccionPortal = 0;
public int tAccionConfig = 5;
public int tAccionLogout = 5;
public boolean isLogout = false;
public boolean isHeroLoaded = false;
public boolean isMoviendo = false;
private Timer movimiento;
private int GG;
private int laser1 = 1;
public int permitirGrupo = 0;
public Usuarios(int id, String usuario, String password, String email, int servidor, String fecha_nacimiento, String pais, String empresa, int premium, String fecha_creacion, long experiencia, int nivel, double jackpot, long creditos, long uridium, int energia_extra, int nave, int gfx, String vants, int skylab, int tecnofabrica, String ciudad, int edad, int sexo, String intereses, String mensaje_estado, int ficheros, int pi, int habilidades, int clan, int estado, int acceso, int rango, long honor, int bono_reparacion, int bono_teleportacion, int llaves, int puertas_alfa, int puertas_beta, int puertas_delta, int puertas_omega, int mapa, String pos, long hp, long hpMax, long escudo, long escudoMax, int vel, long carga, long cargaMax, String inventario, String slot2, String slot3, String slot4, String mun1, String mun2, String mun3, int invisible, String titulo, String lastIP, String ultimaConexion)
{
this.id = id;
this.usuario = usuario;
this.password = password;
this.email = email;
this.servidor = servidor;
this.fecha_nacimiento = fecha_nacimiento;
this.pais = pais;
this.empresa = empresa;
this.premium = premium;
this.fecha_creacion = fecha_creacion;
this.experiencia = experiencia;
this.nivel = nivel;
this.jackpot = jackpot;
this.creditos = creditos;
this.uridium = uridium;
this.energia_extra = energia_extra;
this.nave = nave;
this.gfx = gfx;
this.vants = vants;
this.skylab = skylab;
this.tecnofabrica = tecnofabrica;
this.ciudad = ciudad;
this.edad = edad;
this.sexo = sexo;
this.intereses = intereses;
this.mensaje_estado = mensaje_estado;
this.ficheros = ficheros;
this.pi = pi;
this.habilidades = habilidades;
this.clan = clan;
this.estado = estado;
this.acceso = acceso;
this.rango = rango;
this.honor = honor;
this.bono_reparacion = bono_reparacion;
this.bono_teleportacion = bono_teleportacion;
this.llaves = llaves;
this.puertas_alfa = puertas_alfa;
this.puertas_beta = puertas_beta;
this.puertas_delta = puertas_delta;
this.puertas_omega = puertas_omega;
this.mapa = mapa;
this.pos = pos;
if ((hp < 0L) || (hp == 0L)) hp = 1000L;
this.hp = hp;
this.hpMax = hpMax;
this.escudo = escudo;
this.escudoMax = escudoMax;
this.vel = vel;
this.carga = carga;
this.cargaMax = cargaMax;
this._inventario = inventario;
this.inventario = new Inventario(this);
this.slot2 = slot2;
this.slot3 = slot3;
this.slot4 = slot4;
this.mun1 = mun1;
this.mun2 = mun2;
this.mun3 = mun3;
this.invisible = invisible;
this.titulo = titulo;
this.lastIP = lastIP;
this.ultimaConexion = ultimaConexion;
this.userSetting = Usuarios.Settings.getSettingByUserID(id);
}
public int getId()
{
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getUsuario() {
return this.usuario;
}
public void setUsuario(String usuario) {
this.usuario = usuario;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public Usuarios get_cuenta() {
return this._cuenta;
}
public boolean isOnline()
{
if (this._gameThread != null) return true;
return false;
}
public GameThread getGameThread()
{
return this._gameThread;
}
public ChatThread getChatThread()
{
return this._chatThread;
}
public void desconexion()
{
this._actualUsuario = null;
this._gameThread = null;
this._chatThread = null;
this._actualIP = "";
SQLManager.DESCONECTAR_USUARIO(getId(), 0);
resetAllChars(true);
SQLManager.ACTUALIZAR_DATOS_USUARIO(this);
}
public void resetAllChars(boolean save)
{
set_isOnline(false);
resetVars();
if (save) SQLManager.GUARDAR_USUARIO(this);
this._user.clear();
}
private void resetVars() {}
public long getLastPacketTime()
{
return this._lastPacketTime;
}
public void refreshLastPacketTime()
{
this._lastPacketTime = System.currentTimeMillis();
}
public boolean get_isOnline() {
return this._isOnline;
}
public void set_isOnline(boolean _isOnline) {
this._isOnline = _isOnline;
}
public String get_actualIP() {
return this._actualIP;
}
public void set_actualIP(String _actualIP) {
this._actualIP = _actualIP;
}
public Usuarios get_actualUsuario() {
return this._actualUsuario;
}
public void set_actualUsuario(Usuarios _actualUsuario) {
this._actualUsuario = _actualUsuario;
}
public void setGameThread(GameThread t)
{
this._gameThread = t;
}
public void setChatThread(ChatThread t)
{
this._chatThread = t;
}
public int getServidor() {
return this.servidor;
}
public void setServidor(int servidor) {
this.servidor = servidor;
}
public String getFecha_nacimiento() {
return this.fecha_nacimiento;
}
public void setFecha_nacimiento(String fecha_nacimiento) {
this.fecha_nacimiento = fecha_nacimiento;
}
public String getPais() {
return this.pais;
}
public void setPais(String pais) {
this.pais = pais;
}
public String getEmpresa() {
return this.empresa;
}
public void setEmpresa(String empresa) {
this.empresa = empresa;
}
public int getPremium() {
return this.premium;
}
public void setPremium(int premium) {
this.premium = premium;
}
public String getFecha_creacion() {
return this.fecha_creacion;
}
public void setFecha_creacion(String fecha_creacion) {
this.fecha_creacion = fecha_creacion;
}
public long getExperiencia() {
return this.experiencia;
}
public void setExperiencia(long experiencia) {
this.experiencia = experiencia;
}
public int getNivel() {
return this.nivel;
}
public void setNivel(int nivel) {
this.nivel = nivel;
}
public double getJackpot() {
return this.jackpot;
}
public void setJackpot(double jackpot) {
this.jackpot = jackpot;
}
public long getCreditos() {
return this.creditos;
}
public void setCreditos(long creditos) {
this.creditos = creditos;
}
public long getUridium() {
return this.uridium;
}
public void setUridium(long uridium) {
this.uridium = uridium;
}
public int getEnergia_extra() {
return this.energia_extra;
}
public void setEnergia_extra(int energia_extra) {
this.energia_extra = energia_extra;
}
public int getNave() {
return this.nave;
}
public void setNave(int nave) {
this.nave = nave;
}
public String getVants() {
return this.vants;
}
public void setVants(String vants) {
this.vants = vants;
}
public int getSkylab() {
return this.skylab;
}
public void setSkylab(int skylab) {
this.skylab = skylab;
}
public int getTecnofabrica() {
return this.tecnofabrica;
}
public void setTecnofabrica(int tecnofabrica) {
this.tecnofabrica = tecnofabrica;
}
public String getCiudad() {
return this.ciudad;
}
public void setCiudad(String ciudad) {
this.ciudad = ciudad;
}
public int getEdad() {
return this.edad;
}
public void setEdad(int edad) {
this.edad = edad;
}
public int getSexo() {
return this.sexo;
}
public void setSexo(int sexo) {
this.sexo = sexo;
}
public String getIntereses() {
return this.intereses;
}
public void setIntereses(String intereses) {
this.intereses = intereses;
}
public String getMensaje_estado() {
return this.mensaje_estado;
}
public void setMensaje_estado(String mensaje_estado) {
this.mensaje_estado = mensaje_estado;
}
public int getFicheros() {
return this.ficheros;
}
public void setFicheros(int ficheros) {
this.ficheros = ficheros;
}
public int getPi() {
return this.pi;
}
public void setPi(int pi) {
this.pi = pi;
}
public int getHabilidades() {
return this.habilidades;
}
public void setHabilidades(int habilidades) {
this.habilidades = habilidades;
}
public int getClan() {
return this.clan;
}
public void setClan(int clan) {
this.clan = clan;
}
public int getEstado() {
return this.estado;
}
public void setEstado(int estado) {
this.estado = estado;
}
public int getAcceso() {
return this.acceso;
}
public void setAcceso(int acceso) {
this.acceso = acceso;
}
public int getRango() {
return this.rango;
}
public void setRango(int rango) {
this.rango = rango;
}
public long getHonor() {
return this.honor;
}
public void setHonor(long honor) {
this.honor = honor;
}
public int getBono_reparacion() {
return this.bono_reparacion;
}
public void setBono_reparacion(int bono_reparacion) {
this.bono_reparacion = bono_reparacion;
}
public int getBono_teleportacion() {
return this.bono_teleportacion;
}
public void setBono_teleportacion(int bono_teleportacion) {
this.bono_teleportacion = bono_teleportacion;
}
public int getLlaves() {
return this.llaves;
}
public void setLlaves(int llaves) {
this.llaves = llaves;
}
public int getPuertas_alfa() {
return this.puertas_alfa;
}
public void setPuertas_alfa(int puertas_alfa) {
this.puertas_alfa = puertas_alfa;
}
public int getPuertas_beta() {
return this.puertas_beta;
}
public void setPuertas_beta(int puertas_beta) {
this.puertas_beta = puertas_beta;
}
public int getPuertas_delta() {
return this.puertas_delta;
}
public void setPuertas_delta(int puertas_delta) {
this.puertas_delta = puertas_delta;
}
public int getPuertas_omega() {
return this.puertas_omega;
}
public void setPuertas_omega(int puertas_omega) {
this.puertas_omega = puertas_omega;
}
public int getMapa() {
return this.mapa;
}
public void setMapa(int mapa) {
this.mapa = mapa;
}
public String getPos() {
return this.pos;
}
public void setPos(String pos) {
this.pos = pos;
}
public long getHp() {
return this.hp;
}
public void setHp(long hp) {
this.hp = hp;
}
public int getVel() {
return this.vel;
}
public void setVel(int vel) {
this.vel = vel;
}
public long getCarga() {
return this.carga;
}
public void setCarga(long carga) {
this.carga = carga;
}
public String getSlot2() {
return this.slot2;
}
public void setSlot2(String slot2) {
this.slot2 = slot2;
}
public String getSlot3() {
return this.slot3;
}
public void setSlot3(String slot3) {
this.slot3 = slot3;
}
public String getSlot4() {
return this.slot4;
}
public void setSlot4(String slot4) {
this.slot4 = slot4;
}
public String getMun1() {
return this.mun1;
}
public void setMun1(String mun1) {
this.mun1 = mun1;
}
public String getMun2() {
return this.mun2;
}
public void setMun2(String mun2) {
this.mun2 = mun2;
}
public String getMun3() {
return this.mun3;
}
public void setMun3(String mun3) {
this.mun3 = mun3;
}
public String getLastIP() {
return this.lastIP;
}
public void setLastIP(String lastIP) {
this.lastIP = lastIP;
}
public String getUltimaConexion() {
return this.ultimaConexion;
}
public void setUltimaConexion(String ultimaConexion) {
this.ultimaConexion = ultimaConexion;
}
public long getEscudo() {
return this.escudo;
}
public void setEscudo(long escudo) {
this.escudo = escudo;
}
public boolean esPremium(int id)
{
boolean esPremium = false;
if (id == 1)
{
esPremium = true;
}
else {
esPremium = false;
}
return esPremium;
}
public static Map<Integer, Usuarios> getConectados() {
return conectados;
}
public static void setConectados(int id, Usuarios user)
{
conectados.put(Integer.valueOf(id), user);
}
public void autoPilotar(int posX, int posY)
{
String HeroPacket = "RDY|" + ServerCommands.HERO_MOVEMENT + "|" + posX + "|" + posY;
SocketManager.send(this, HeroPacket);
}
public int getInvisible() {
return this.invisible;
}
public void setInvisible(int invisible) {
this.invisible = invisible;
}
public int getGG() {
this.GG = (this.puertas_alfa + this.puertas_beta + this.puertas_delta + this.puertas_omega);
if (this.GG > 4) this.GG = 4;
return this.GG;
}
public void setGG(int gG) {
if (gG > 4) gG = 4;
this.GG = gG;
}
public String getTagClan()
{
String tagClan = "";
if ((World.getClanByID(this.clan) != null) && (World.getClanByID(this.clan).getClanID() == this.clan))
{
tagClan = World.getClanByID(this.clan).getTagNombre();
}
return tagClan;
}
public String getTitulo()
{
return this.titulo;
}
public void setTitulo(String titulo) {
this.titulo = titulo;
}
public long getHpMax() {
return this.hpMax;
}
public void setHpMax(long hpMax) {
this.hpMax = hpMax;
}
public long getEscudoMax() {
return this.escudoMax;
}
public void setEscudoMax(long escudoMax) {
this.escudoMax = escudoMax;
}
public long getCargaMax() {
return this.cargaMax;
}
public void setCargaMax(long cargaMax) {
this.cargaMax = cargaMax;
}
public void acciones()
{
this.tAccionPortal -= 1;
if (this.tAccionPortal < 0) this.tAccionPortal = 0;
this.tAccionConfig -= 1;
if (this.tAccionConfig < 0) this.tAccionConfig = 0;
if (this.isLogout)
{
if (this.tAccionLogout == 0)
{
this.isLogout = false;
this.tAccionLogout = 5;
SocketManager.send(this, "0|" + ServerCommands.LOGOUT);
desconexion();
}
this.tAccionLogout -= 1;
if (this.tAccionLogout < 0) this.tAccionLogout = 0;
}
}
public int getLaser1()
{
return this.laser1;
}
public void setLaser1(int laser1) {
this.laser1 = laser1;
}
public int getOldPosX() {
return this.oldPosX;
}
public void setOldPosX(int oldPosX) {
this.oldPosX = oldPosX;
}
public int getOldPosY() {
return this.oldPosY;
}
public void setOldPosY(int oldPosY) {
this.oldPosY = oldPosY;
}
public Usuarios.Settings getUserSetting() {
return this.userSetting;
}
public void setUserSetting(Usuarios.Settings userSetting) {
this.userSetting = userSetting;
}
public Mapas getMapaActual()
{
return World.getMapaByID(this.mapa);
}
public Ship getShip() {
return this.ship;
}
public void setShip(Ship ship) {
this.ship = ship;
}
public String getSessionID() {
return this.sessionID;
}
public void setSessionID(String sessionID) {
this.sessionID = sessionID;
}
public int getGfx() {
return this.gfx;
}
public void setGfx(int gfx) {
this.gfx = gfx;
}
public Inventario getInventario() {
return this.inventario;
}
public void setInventario(Inventario inventario) {
this.inventario = inventario;
}
public String get_inventario() {
return this._inventario;
}
public void set_inventario(String _inventario) {
this._inventario = _inventario;
}
}
Code:
package common;
import game.Clanes;
import game.Mapas;
import game.NPC;
import game.Naves;
import game.Portales;
import game.Ship;
import game.Usuarios;
import game.Usuarios.Settings;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
public class World
{
private static Map<Integer, Usuarios> Usuarios = new TreeMap();
private static Map<String, Integer> UsuariobyNombre = new TreeMap();
private static Map<Integer, Usuarios.Settings> Settings = new TreeMap();
private static Map<Integer, Mapas> Mapas = new TreeMap();
private static Map<Integer, Naves> Naves = new TreeMap();
private static Map<Integer, NPC> NPCs = new TreeMap();
private static Map<Integer, Portales> Portales = new TreeMap();
private static Map<Integer, Clanes> Clanes = new TreeMap();
private static Map<Integer, World.ExpLevel> ExpLevels = new TreeMap();
private static int nextObjetoID;
private static int saveTry = 1;
private static short _state = 1;
public static void addUsuario(Usuarios usuario)
{
Usuarios.put(Integer.valueOf(usuario.getId()), usuario);
UsuariobyNombre.put(usuario.getUsuario().toLowerCase(), Integer.valueOf(usuario.getId()));
}
public static void addUsuariobyNombre(Usuarios usuario)
{
UsuariobyNombre.put(usuario.getUsuario(), Integer.valueOf(usuario.getId()));
}
public static void addExpLevel(int lvl, World.ExpLevel exp)
{
ExpLevels.put(Integer.valueOf(lvl), exp);
}
public static World.ExpLevel getExpLevel(int lvl)
{
return (World.ExpLevel)ExpLevels.get(Integer.valueOf(lvl));
}
public static long getUserXpMin(int lvl)
{
if (lvl > 32) lvl = 32;
if (lvl < 1) lvl = 1;
return ((World.ExpLevel)ExpLevels.get(Integer.valueOf(lvl))).nave;
}
public static long getUserXpMax(int lvl)
{
int up = 0;
if (lvl >= 32) lvl = 32;
if (lvl <= 1) lvl = 1;
if (lvl < 32) up = 1;
return ((World.ExpLevel)ExpLevels.get(Integer.valueOf(lvl + up))).nave;
}
public static void createWorld()
{
System.out.println("Cargando cuenta(s)...");
SQLManager.CARGAR_SETTINGS();
SQLManager.CARGAR_USUARIOS();
System.out.println(Usuarios.size() + " cuentas creada(s).");
System.out.println("Cargando alien(s)...");
SQLManager.CARGAR_NPCS();
System.out.println(NPCs.size() + " alien(s) cargado(s).");
System.out.println("Cargando nivel(es) de experiencia...");
SQLManager.CARGAR_XP();
System.out.println(ExpLevels.size() + " nivel(es) cargado(s).");
System.out.println("Cargando mapa(s)...");
SQLManager.CARGAR_MAPAS();
System.out.println(Mapas.size() + " mapa(s) cargado(s).");
System.out.println("Cargando nave(s)...");
SQLManager.CARGAR_NAVES();
System.out.println(Naves.size() + " nave(s) cargada(s).");
System.out.println("Cargando portal(es)...");
SQLManager.CARGAR_PORTALES();
System.out.println(Portales.size() + " portal(es) cargado(s).");
System.out.println("Cargando clan(es)...");
SQLManager.CARGAR_CLANES();
System.out.println(Clanes.size() + " clan(es) cargado(s).");
System.out.print("Estados de conexion reseteados: ");
SQLManager.LOGGED_ZERO();
System.out.println("Correcto!");
System.out.println("Cargando lista de baneados...");
int nbr = SQLManager.CARGAR_BANEADOS();
System.out.println(nbr + " baneados.");
nextObjetoID = SQLManager.getNextObjetoID();
}
public static synchronized int getNewObjetoId()
{
return nextObjetoID++;
}
public static Usuarios getUsuarioByID(int id)
{
return (Usuarios)Usuarios.get(Integer.valueOf(id));
}
public static Usuarios getUsuarioByNombre(String usuario)
{
return UsuariobyNombre.get(usuario.toLowerCase()) != null ? (Usuarios)Usuarios.get(UsuariobyNombre.get(usuario.toLowerCase())) : null;
}
public static void addMapa(Mapas mapa)
{
Mapas.put(Integer.valueOf(mapa.getMapid()), mapa);
}
public static void addNaves(Naves nave)
{
Naves.put(Integer.valueOf(nave.getId()), nave);
}
public static Clanes getClanByID(int id)
{
return (Clanes)Clanes.get(Integer.valueOf(id));
}
public static void addPortales(Portales portal)
{
Portales.put(Integer.valueOf(portal.getID()), portal);
}
public static void addClanes(Clanes clan)
{
Clanes.put(Integer.valueOf(clan.getClanID()), clan);
}
public static Naves getNavesByID(int id)
{
return (Naves)Naves.get(Integer.valueOf(id));
}
public static List<Usuarios> getUsuariosOnline()
{
List<Usuarios> online = new ArrayList();
for (Map.Entry<Integer, Usuarios> user : Usuarios.entrySet())
{
if ((((Usuarios)user.getValue()).isOnline()) && (((Usuarios)user.getValue()).getGameThread() != null))
{
if (((Usuarios)user.getValue()).getGameThread().get_out() != null)
{
online.add((Usuarios)user.getValue());
}
}
}
return online;
}
public static List<Portales> getPortales()
{
List<Portales> portal = new ArrayList();
for (Map.Entry<Integer, Portales> p : Portales.entrySet())
{
portal.add((Portales)p.getValue());
}
return portal;
}
public static List<Mapas> getMapas()
{
List<Mapas> mapa = new ArrayList();
for (Map.Entry<Integer, Mapas> m : Mapas.entrySet())
{
mapa.add((Mapas)m.getValue());
}
return mapa;
}
public static void saveAll(Usuarios saver)
{
java.io.PrintWriter _out = null;
if (saver != null) {
_out = saver.get_cuenta().getGameThread().get_out();
}
set_state((short)2);
try
{
System.out.println("Lanzamiento de autoguardado...");
DarkOrbit.isSaving = true;
SQLManager.commitTransacts();
SQLManager.TIMER(false);
Thread.sleep(10000L);
System.out.println("Guardando cuentas...");
for (Usuarios user : Usuarios.values())
{
if (user.isOnline()) {
Thread.sleep(100L);
SQLManager.GUARDAR_USUARIO(user);
} }
Thread.sleep(2500L);
System.out.println("Guardado con exito !");
set_state((short)1);
}
catch (ConcurrentModificationException e)
{
if (saveTry < 10)
{
System.out.println("Nueva tentativa de guardado");
if ((saver != null) && (_out != null))
System.out.println("Error. Nueva tentativa de guardado.");
saveTry += 1;
saveAll(saver);
}
else
{
set_state((short)1);
String mess = "Error al guardar despues de " + saveTry + " tentativas";
if ((saver != null) && (_out != null))
System.out.println(mess);
}
}
catch (Exception e)
{
System.out.println("Error al guardar los datos : " + e.getMessage());
e.printStackTrace();
}
finally
{
SQLManager.commitTransacts();
SQLManager.TIMER(true);
DarkOrbit.isSaving = false;
saveTry = 1;
}
}
public static void set_state(short state)
{
_state = state;
}
public static void MoveAliensOnMaps() {
Iterator localIterator2;
for (Iterator localIterator1 = getUsuariosOnline().iterator(); localIterator1.hasNext();
localIterator2.hasNext())
{
Usuarios user = (Usuarios)localIterator1.next();
localIterator2 = user.getMapaActual().get_aliens().values().iterator();continue;Ship aliens = (Ship)localIterator2.next();
if (aliens.getId() < 0)
{
new IA.IAThread(aliens);
}
}
}
public static void addNPC(NPC npc)
{
NPCs.put(Integer.valueOf(npc.getId()), npc);
}
public static void addSettings(Usuarios.Settings s) {
Settings.put(Integer.valueOf(s.getUserID()), s);
}
public static Usuarios.Settings getSettingByID(int id)
{
return (Usuarios.Settings)Settings.get(Integer.valueOf(id));
}
public static NPC getNPC(int id)
{
return (NPC)NPCs.get(Integer.valueOf(id));
}
public static Mapas getMapaByID(int id)
{
return (Mapas)Mapas.get(Integer.valueOf(id));
}
}
Code:
package common;
import game.Naves;
import game.Portales;
import game.Usuarios;
import java.io.PrintStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Timer;
public class SQLManager
{
private static Connection conexion;
private static Timer timerCommit;
private static boolean needCommit;
public static synchronized ResultSet executeQuery(String query, String DBNAME) throws SQLException
{
if (!DarkOrbit.isInit) {
return null;
}
Connection DB = conexion;
Statement stat = DB.createStatement();
ResultSet RS = stat.executeQuery(query);
stat.setQueryTimeout(300);
return RS;
}
public static synchronized PreparedStatement newTransact(String baseQuery, Connection dbCon) throws SQLException
{
PreparedStatement toReturn = dbCon.prepareStatement(baseQuery);
needCommit = true;
return toReturn;
}
public static synchronized void closeCons()
{
try
{
commitTransacts();
conexion.close();
}
catch (Exception e) {
System.out.println("Error al cerrar la conexion SQL:" + e.getMessage());
e.printStackTrace();
}
}
public static synchronized void commitTransacts()
{
try
{
if (conexion.isClosed())
{
closeCons();
setUpConnexion();
}
conexion.commit();
}
catch (SQLException e) {
System.out.println("SQL ERROR:" + e.getMessage());
e.printStackTrace();
commitTransacts();
}
}
public static final boolean setUpConnexion()
{
try
{
conexion = java.sql.DriverManager.getConnection("jdbc:mysql://" + DarkOrbit.HOST + "/" + DarkOrbit.BD, DarkOrbit.USUARIO, DarkOrbit.PASSWORD);
conexion.setAutoCommit(false);
if (!conexion.isValid(1000))
{
System.out.println("SQLError : Conexion incorrecta a la BD!");
return false;
}
needCommit = false;
TIMER(true);
return true;
}
catch (SQLException e) {
System.out.println("SQL ERROR: " + e.getMessage());
e.printStackTrace(); }
return false;
}
public static void TIMER(boolean start)
{
if (start)
{
timerCommit = new Timer();
timerCommit.schedule(new SQLManager.1(),
DarkOrbit.CONFIG_DB_COMMIT);
}
else {
timerCommit.cancel();
}
}
private static void closeResultSet(ResultSet RS) {
try {
RS.getStatement().close();
RS.close();
} catch (SQLException e) { e.printStackTrace();
}
}
private static void closePreparedStatement(PreparedStatement p) {
try {
p.clearParameters();
p.close();
} catch (SQLException e) { e.printStackTrace();
}
}
public static void DESCONECTAR_USUARIO(int userID, int estado)
{
String query = "UPDATE `cuentas` SET estado=? WHERE `id`=?;";
try {
PreparedStatement p = newTransact(query, conexion);
p.setInt(1, estado);
p.setInt(2, userID);
p.execute();
closePreparedStatement(p);
} catch (SQLException e) {
System.out.println("Juego: SQL ERROR: " + e.getMessage());
System.out.println("Juego: Consulta: " + query);
}
}
public static void LOGGED_ZERO()
{
String query = "UPDATE `cuentas` SET estado=0;";
try {
PreparedStatement p = newTransact(query, conexion);
p.execute();
closePreparedStatement(p);
} catch (SQLException e) {
System.out.println("Juego: SQL ERROR: " + e.getMessage());
System.out.println("Juego: Consulta: " + query);
}
}
public static void CARGAR_USUARIOS()
{
try
{
ResultSet RS = executeQuery("SELECT * from cuentas;", DarkOrbit.BD);
while (RS.next())
{
Usuarios C = new Usuarios(
RS.getInt("id"),
RS.getString("usuario").toLowerCase(),
RS.getString("password"),
RS.getString("email"),
RS.getInt("servidor"),
RS.getString("fecha_nacimiento"),
RS.getString("pais"),
RS.getString("empresa"),
RS.getInt("premium"),
RS.getString("fecha_creacion"),
RS.getLong("experiencia"),
RS.getInt("nivel"),
RS.getDouble("jackpot"),
RS.getLong("creditos"),
RS.getLong("uridium"),
RS.getInt("energia_extra"),
RS.getInt("nave"),
RS.getInt("gfx"),
RS.getString("vants"),
RS.getInt("skylab"),
RS.getInt("tecnofabrica"),
RS.getString("ciudad"),
RS.getInt("edad"),
RS.getInt("sexo"),
RS.getString("intereses"),
RS.getString("mensaje_estado"),
RS.getInt("ficheros"),
RS.getInt("pi"),
RS.getInt("habilidades"),
RS.getInt("clan"),
RS.getInt("estado"),
RS.getInt("acceso"),
RS.getInt("rango"),
RS.getLong("honor"),
RS.getInt("bono_reparacion"),
RS.getInt("bono_teleportacion"),
RS.getInt("llaves"),
RS.getInt("puertas_alfa"),
RS.getInt("puertas_beta"),
RS.getInt("puertas_delta"),
RS.getInt("puertas_omega"),
RS.getInt("mapa"),
RS.getString("pos"),
RS.getLong("hp"),
RS.getLong("hpMax"),
RS.getLong("escudo"),
RS.getLong("escudoMax"),
RS.getInt("vel"),
RS.getLong("carga"),
RS.getLong("cargaMax"),
RS.getString("inventario"),
RS.getString("slot2"),
RS.getString("slot3"),
RS.getString("slot4"),
RS.getString("mun1"),
RS.getString("mun2"),
RS.getString("mun3"),
RS.getInt("invisible"),
RS.getString("titulo"),
RS.getString("lastIP"),
RS.getString("ultimaConexion"));
World.addUsuario(C);
World.addUsuariobyNombre(C);
}
closeResultSet(RS);
}
catch (SQLException e) {
System.out.println("SQL ERROR: " + e.getMessage());
e.printStackTrace();
}
}
public static int getNextUsuarioId()
{
try
{
ResultSet RS = executeQuery("SELECT id FROM cuentas ORDER BY id DESC LIMIT 1;", DarkOrbit.BD);
if (!RS.first()) return 1;
int id = RS.getInt("id");
id++;
closeResultSet(RS);
return id;
}
catch (SQLException e) {
System.out.println("SQL ERROR: " + e.getMessage());
e.printStackTrace();
DarkOrbit.closeServers();
}
return 0;
}
public static int getNextObjetoID()
{
try
{
ResultSet RS = executeQuery("SELECT MAX(id) AS max FROM objetos;", DarkOrbit.BD);
int id = 0;
boolean found = RS.first();
if (found) {
id = RS.getInt("max");
}
closeResultSet(RS);
return id;
}
catch (SQLException e) {
System.out.println("SQL ERROR: " + e.getMessage());
e.printStackTrace();
DarkOrbit.closeServers();
}
return 0;
}
public static void CARGAR_NAVES()
{
try
{
ResultSet RS = executeQuery("SELECT * from naves;", DarkOrbit.BD);
while (RS.next())
{
Naves N = new Naves(
RS.getInt("id"),
RS.getString("nombre"),
RS.getInt("velocidad"),
RS.getInt("carga"),
RS.getInt("lasers"),
RS.getInt("generadores"),
RS.getLong("vida"),
RS.getInt("misiles"),
RS.getInt("extras"));
World.addNaves(N);
}
closeResultSet(RS);
}
catch (SQLException e) {
System.out.println("SQL ERROR: " + e.getMessage());
e.printStackTrace();
}
}
public static void CARGAR_PORTALES()
{
try
{
ResultSet RS = executeQuery("SELECT * from portales;", DarkOrbit.BD);
while (RS.next())
{
Portales P = new Portales(
RS.getInt("ID"),
RS.getInt("factionID"),
RS.getInt("keyPortal"),
RS.getInt("mapID"),
RS.getInt("posX"),
RS.getInt("posY"),
RS.getInt("factionScrap"),
RS.getInt("toMapID"),
RS.getString("toPos"),
RS.getInt("reqNivel"));
World.addPortales(P);
}
closeResultSet(RS);
}
catch (SQLException e) {
System.out.println("SQL ERROR: " + e.getMessage());
e.printStackTrace();
}
}
public static void CARGAR_CLANES()
{
try
{
ResultSet RS = executeQuery("SELECT * from clanes;", DarkOrbit.BD);
while (RS.next())
{
game.Clanes C = new game.Clanes(
RS.getInt("clanID"),
RS.getString("nombre"),
RS.getString("tagNombre"));
World.addClanes(C);
}
closeResultSet(RS);
}
catch (SQLException e) {
System.out.println("SQL ERROR: " + e.getMessage());
e.printStackTrace();
}
}
public static void CARGAR_MAPAS()
{
try
{
ResultSet RS = executeQuery("SELECT * from mapas;", DarkOrbit.BD);
while (RS.next())
{
game.Mapas M = new game.Mapas(
RS.getInt("mapid"),
RS.getString("name"),
RS.getInt("music"),
RS.getInt("scaleFactor"),
RS.getString("neighbours"),
RS.getString("starfield"),
RS.getString("backgrounds"),
RS.getString("lensflares"),
RS.getString("planets"),
RS.getString("aliens"));
World.addMapa(M);
}
closeResultSet(RS);
}
catch (SQLException e) {
System.out.println("SQL ERROR: " + e.getMessage());
e.printStackTrace();
}
}
public static void CARGAR_NPCS()
{
try
{
ResultSet RS = executeQuery("SELECT * from npcs;", DarkOrbit.BD);
while (RS.next())
{
game.NPC N = new game.NPC(
RS.getInt("id"),
RS.getString("nombre"),
RS.getInt("gfx"),
RS.getInt("pv"),
RS.getInt("esc"),
RS.getInt("exp"),
RS.getInt("hon"),
RS.getInt("cre"),
RS.getInt("uri"),
RS.getInt("xenomit"),
RS.getInt("prometium"),
RS.getInt("terbium"),
RS.getInt("endurium"),
RS.getInt("prometid"),
RS.getInt("duranium"),
RS.getInt("promerium"),
RS.getString("dmg"),
RS.getInt("IA"));
World.addNPC(N);
}
closeResultSet(RS);
}
catch (SQLException e) {
System.out.println("SQL ERROR: " + e.getMessage());
e.printStackTrace();
}
}
public static void CARGAR_SETTINGS()
{
try
{
ResultSet RS = executeQuery("SELECT * from settings;", DarkOrbit.BD);
while (RS.next())
{
game.Usuarios.Settings S = new game.Usuarios.Settings(
RS.getInt("userID"),
RS.getString("SET"),
RS.getString("MINIMAP_SCALE"),
RS.getString("DISPLAY_PLAYER_NAMES"),
RS.getString("DISPLAY_CHAT"),
RS.getString("PLAY_MUSIC"),
RS.getString("PLAY_SFX"),
RS.getString("BAR_STATUS"),
RS.getString("WINDOW_SETTINGS"),
RS.getString("AUTO_REFINEMENT"),
RS.getString("QUICKSLOT_STOP_ATTACK"),
RS.getString("DOUBLECLICK_ATTACK"),
RS.getString("AUTO_START"),
RS.getString("DISPLAY_NOTIFICATIONS"),
RS.getString("SHOW_DRONES"),
RS.getString("DISPLAY_WINDOW_BACKGROUND"),
RS.getString("ALWAYS_DRAGGABLE_WINDOWS"),
RS.getString("PRELOAD_USER_SHIPS"),
RS.getString("QUALITY_PRESETTING"),
RS.getString("QUALITY_CUSTOMIZED"),
RS.getString("QUALITY_BACKGROUND"),
RS.getString("QUALITY_POIZONE"),
RS.getString("QUALITY_SHIP"),
RS.getString("QUALITY_ENGINE"),
RS.getString("QUALITY_COLLECTABLE"),
RS.getString("QUALITY_ATTACK"),
RS.getString("QUALITY_EFFECT"),
RS.getString("QUALITY_EXPLOSION"),
RS.getString("QUICKBAR_SLOT"),
RS.getString("SLOTMENU_POSITION"),
RS.getString("SLOTMENU_ORDER"));
World.addSettings(S);
}
closeResultSet(RS);
}
catch (SQLException e) {
System.out.println("SQL ERROR: " + e.getMessage());
e.printStackTrace();
}
}
public static void ACTUALIZAR_DATOS_USUARIO(Usuarios user)
{
try
{
String baseQuery = "UPDATE cuentas SET `usuario` = ?,`password` = ?,`email` = ?,`servidor` = ?,`fecha_nacimiento` = ?,`pais` = ?,`empresa` = ?,`premium` = ?,`fecha_creacion` = ?,`experiencia` = ?,`nivel` = ?,`jackpot` = ?,`creditos` = ?,`uridium` = ?,`energia_extra` = ?,`nave` = ?,`gfx` = ?,`vants` = ?,`skylab` = ?,`tecnofabrica` = ?,`ciudad` = ?,`edad` = ?,`sexo` = ?,`intereses` = ?,`mensaje_estado` = ?,`ficheros` = ?,`pi` = ?,`habilidades` = ?,`clan` = ?,`estado` = ?,`acceso` = ?,`rango` = ?,`honor` = ?,`bono_reparacion` = ?,`bono_teleportacion` = ?,`llaves` = ?,`puertas_alfa` = ?,`puertas_beta` = ?,`puertas_delta` = ?,`puertas_omega` = ?,`mapa` = ?,`pos` = ?,`hp` = ?,`hpMax` = ?,`escudo` = ?,`escudoMax` = ?,`vel` = ?,`carga` = ?,`cargaMax` = ?,`inventario` = ?,`slot2` = ?,`slot3` = ?,`slot4` = ?,`mun1` = ?,`mun2` = ?,`mun3` = ?,`invisible` = ?,`titulo` = ?,`lastIP` = ?,`ultimaConexion` = ? WHERE `id` = ?;";
PreparedStatement p = newTransact(baseQuery, conexion);
p.setString(1, user.getUsuario());
p.setString(2, user.getPassword());
p.setString(3, user.getEmail());
p.setInt(4, user.getServidor());
p.setString(5, user.getFecha_nacimiento());
p.setString(6, user.getPais());
p.setString(7, user.getEmpresa());
p.setInt(8, user.getPremium());
p.setString(9, user.getFecha_creacion());
p.setLong(10, user.getExperiencia());
p.setInt(11, user.getNivel());
p.setDouble(12, user.getJackpot());
p.setLong(13, user.getCreditos());
p.setLong(14, user.getUridium());
p.setInt(15, user.getEnergia_extra());
p.setInt(16, user.getNave());
p.setInt(17, user.getGfx());
p.setString(18, user.getVants());
p.setInt(19, user.getSkylab());
p.setInt(20, user.getTecnofabrica());
p.setString(21, user.getCiudad());
p.setInt(22, user.getEdad());
p.setInt(23, user.getSexo());
p.setString(24, user.getIntereses());
p.setString(25, user.getMensaje_estado());
p.setInt(26, user.getFicheros());
p.setInt(27, user.getPi());
p.setInt(28, user.getHabilidades());
p.setInt(29, user.getClan());
p.setInt(30, user.getEstado());
p.setInt(31, user.getAcceso());
p.setInt(32, user.getRango());
p.setLong(33, user.getHonor());
p.setInt(34, user.getBono_reparacion());
p.setInt(35, user.getBono_teleportacion());
p.setInt(36, user.getLlaves());
p.setInt(37, user.getPuertas_alfa());
p.setInt(38, user.getPuertas_beta());
p.setInt(39, user.getPuertas_delta());
p.setInt(40, user.getPuertas_omega());
p.setInt(41, user.getMapa());
p.setString(42, user.getPos());
p.setLong(43, user.getHp());
p.setLong(44, user.getHpMax());
p.setLong(45, user.getEscudo());
p.setLong(46, user.getEscudoMax());
p.setInt(47, user.getVel());
p.setLong(48, user.getCarga());
p.setLong(49, user.getCargaMax());
p.setString(50, user.get_inventario());
p.setString(51, user.getSlot2());
p.setString(52, user.getSlot3());
p.setString(53, user.getSlot4());
p.setString(54, user.getMun1());
p.setString(55, user.getMun2());
p.setString(56, user.getMun3());
p.setInt(57, user.getInvisible());
p.setString(58, user.getTitulo());
p.setString(59, user.getLastIP());
p.setString(60, user.getUltimaConexion());
p.setInt(61, user.getId());
p.executeUpdate();
closePreparedStatement(p);
}
catch (SQLException e) {
System.out.println("SQL ERROR: " + e.getMessage());
e.printStackTrace();
}
}
public static void GUARDAR_USUARIO(Usuarios user)
{
try
{
String baseQuery = "UPDATE cuentas SET `usuario` = ?,`password` = ?,`email` = ?,`servidor` = ?,`fecha_nacimiento` = ?,`pais` = ?,`empresa` = ?,`premium` = ?,`fecha_creacion` = ?,`experiencia` = ?,`nivel` = ?,`jackpot` = ?,`creditos` = ?,`uridium` = ?,`energia_extra` = ?,`nave` = ?,`gfx` = ?,`vants` = ?,`skylab` = ?,`tecnofabrica` = ?,`ciudad` = ?,`edad` = ?,`sexo` = ?,`intereses` = ?,`mensaje_estado` = ?,`ficheros` = ?,`pi` = ?,`habilidades` = ?,`clan` = ?,`estado` = ?,`acceso` = ?,`rango` = ?,`honor` = ?,`bono_reparacion` = ?,`bono_teleportacion` = ?,`llaves` = ?,`puertas_alfa` = ?,`puertas_beta` = ?,`puertas_delta` = ?,`puertas_omega` = ?,`mapa` = ?,`pos` = ?,`hp` = ?,`hpMax` = ?,`escudo` = ?,`escudoMax` = ?,`vel` = ?,`carga` = ?,`cargaMax` = ?,`inventario` = ?,`slot2` = ?,`slot3` = ?,`slot4` = ?,`mun1` = ?,`mun2` = ?,`mun3` = ?,`invisible` = ?,`titulo` = ?,`lastIP` = ?,`ultimaConexion` = ?WHERE `cuentas`.`id` = ? LIMIT 1 ;";
PreparedStatement p = newTransact(baseQuery, conexion);
p.setString(1, user.getUsuario());
p.setString(2, user.getPassword());
p.setString(3, user.getEmail());
p.setInt(4, user.getServidor());
p.setString(5, user.getFecha_nacimiento());
p.setString(6, user.getPais());
p.setString(7, user.getEmpresa());
p.setInt(8, user.getPremium());
p.setString(9, user.getFecha_creacion());
p.setLong(10, user.getExperiencia());
p.setInt(11, user.getNivel());
p.setDouble(12, user.getJackpot());
p.setLong(13, user.getCreditos());
p.setLong(14, user.getUridium());
p.setInt(15, user.getEnergia_extra());
p.setInt(16, user.getNave());
p.setInt(17, user.getGfx());
p.setString(18, user.getVants());
p.setInt(19, user.getSkylab());
p.setInt(20, user.getTecnofabrica());
p.setString(21, user.getCiudad());
p.setInt(22, user.getEdad());
p.setInt(23, user.getSexo());
p.setString(24, user.getIntereses());
p.setString(25, user.getMensaje_estado());
p.setInt(26, user.getFicheros());
p.setInt(27, user.getPi());
p.setInt(28, user.getHabilidades());
p.setInt(29, user.getClan());
p.setInt(30, user.getEstado());
p.setInt(31, user.getAcceso());
p.setInt(32, user.getRango());
p.setLong(33, user.getHonor());
p.setInt(34, user.getBono_reparacion());
p.setInt(35, user.getBono_teleportacion());
p.setInt(36, user.getLlaves());
p.setInt(37, user.getPuertas_alfa());
p.setInt(38, user.getPuertas_beta());
p.setInt(39, user.getPuertas_delta());
p.setInt(40, user.getPuertas_omega());
p.setInt(41, user.getMapa());
p.setString(42, user.getPos());
p.setLong(43, user.getHp());
p.setLong(44, user.getHpMax());
p.setLong(45, user.getEscudo());
p.setLong(46, user.getEscudoMax());
p.setInt(47, user.getVel());
p.setLong(48, user.getCarga());
p.setLong(49, user.getCargaMax());
p.setString(50, user.get_inventario());
p.setString(51, user.getSlot2());
p.setString(52, user.getSlot3());
p.setString(53, user.getSlot4());
p.setString(54, user.getMun1());
p.setString(55, user.getMun2());
p.setString(56, user.getMun3());
p.setInt(57, user.getInvisible());
p.setString(58, user.getTitulo());
p.setString(59, user.getLastIP());
p.setString(60, user.getUltimaConexion());
p.setInt(61, user.getId());
p.executeUpdate();
closePreparedStatement(p);
}
catch (SQLException e) {
System.out.println("SQL ERROR: " + e.getMessage());
e.printStackTrace();
}
}
public static void CARGAR_XP()
{
try
{
ResultSet RS = executeQuery("SELECT * from experiencias;", DarkOrbit.BD);
while (RS.next()) World.addExpLevel(RS.getInt("nivel"), new World.ExpLevel(RS.getLong("nave"), RS.getInt("vant"), RS.getInt("pet")));
closeResultSet(RS);
}
catch (SQLException e) {
System.out.println("Juego: SQL ERROR: " + e.getMessage());
System.exit(1);
}
}
public static int CARGAR_BANEADOS()
{
int i = 0;
try
{
ResultSet RS = executeQuery("SELECT ip from banip;", DarkOrbit.BD);
while (RS.next())
{
Constantes.BAN_IP += RS.getString("ip");
if (!RS.isLast()) Constantes.BAN_IP += ",";
i++;
}
closeResultSet(RS);
}
catch (SQLException e) {
System.out.println("SQL ERROR: " + e.getMessage());
e.printStackTrace();
}
return i;
}
public static boolean AGREGAR_BANEADO(String ip)
{
String baseQuery = "INSERT INTO `banip` VALUES (?);";
try
{
PreparedStatement p = newTransact(baseQuery, conexion);
p.setString(1, ip);
p.execute();
closePreparedStatement(p);
return true;
} catch (SQLException e) {
System.out.println("Juego: SQL ERROR: " + e.getMessage());
System.out.println("Juego: Consulta: " + baseQuery);
}
return false;
}
public static void ACTUALIZAR_POSICION_USUARIO(Usuarios user)
{
try {
String baseQuery = "UPDATE cuentas SET `mapa` = ?,`pos` = ? WHERE `id` = ?;";
PreparedStatement p = newTransact(baseQuery, conexion);
p.setInt(1, user.getMapa());
p.setString(2, user.getPos());
p.setInt(3, user.getId());
p.executeUpdate();
closePreparedStatement(p);
}
catch (SQLException e) {
System.out.println("SQL ERROR: " + e.getMessage());
e.printStackTrace();
}
}
}
Code:
package common;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.net.InetAddress;
import java.util.Calendar;
import net.GameServer;
import net.chat.ChatServer;
import net.logging.SOSLoggingServer;
import policyserver.PolicyServer;
public class DarkOrbit
{
private static final String CONFIG_FILE = "config.ini";
public static String VERSION = "1.0.0";
public static boolean isRunning = false;
public static boolean canLog;
public static boolean isSaving = false;
public static int CONFIG_GAME_PORT = 8080;
public static int CONFIG_CHAT_PORT = 9338;
public static int CONFIG_LOG_PORT = 4444;
public static int CONFIG_SAVE_TIME = 6000000;
public static String GAMESERVER_IP;
public static String CHATSERVER_IP;
public static String LOGSERVER_IP;
public static String IP = "127.0.0.1";
public static boolean CONFIG_USE_IP = true;
public static GameServer gameServer;
public static ChatServer chatServer;
public static SOSLoggingServer logServer;
public static BufferedWriter Log_Game;
public static PrintStream PS;
public static boolean CONFIG_DEBUG = true;
public static boolean CONFIG_MODO_CONSOLA = false;
public static int LANZAR_BONUSBOX = 60;
public static int SIZE_BONUSBOX = 50;
public static int CONFIG_MAX_IDLE_TIME = 300000;
public static String HOST = "127.0.0.1";
public static String BD = "do_es";
public static String USUARIO = "root";
public static String PASSWORD = "";
public static int CONFIG_DB_COMMIT = 30000;
public static boolean isInit = false;
public static PolicyServer policyServer;
private static DarkOrbit _this;
public static void main(String[] args)
{
Runtime.getRuntime().addShutdownHook(new DarkOrbit.1());
System.out.println("#=========================#");
System.out.println("# DarkOrbit v" + VERSION + "\t#");
System.out.println("# Creado por: Elieaz #");
System.out.println("# #");
System.out.println("#=========================#");
System.out.println("Cargando configuracion:");
cargarConfiguracion();
isInit = true;
System.out.println("Cargado con exito!");
System.out.println("Conexion con la Base de datos...");
if (SQLManager.setUpConnexion()) { System.out.println("Conectado!");
}
else {
System.out.println("Conexion invalida");
closeServers();
System.exit(0);
}
System.out.println("Creando DarkOrbit...");
long startTime = System.currentTimeMillis();
System.out.println("Creando Policy Server...");
policyServer = new PolicyServer(_this);
World.createWorld();
long endTime = System.currentTimeMillis();
long differenceTime = (endTime - startTime) / 1000L;
System.out.println("Creado con exito ! en : " + differenceTime + " s");
isRunning = true;
String Ip = "";
try
{
Ip = InetAddress.getLocalHost().getHostAddress();
}
catch (Exception e) {
System.out.println(e.getMessage());
try {
Thread.sleep(10000L);
} catch (InterruptedException localInterruptedException) {}
System.exit(1);
}
Ip = IP;
gameServer = new GameServer(Ip);
System.out.println("Servidor del juego lanzado en el puerto " + CONFIG_GAME_PORT);
chatServer = new ChatServer(Ip);
System.out.println("Servidor del chat lanzado en el puerto " + CONFIG_CHAT_PORT);
logServer = new SOSLoggingServer(Ip);
System.out.println("Servidor de Logs lanzado en el puerto " + CONFIG_LOG_PORT);
if (CONFIG_USE_IP) {
System.out.println("IP del servidor " + IP + " encriptada: " + GAMESERVER_IP);
}
System.out.println("Esperando conexiones...");
}
public static void cargarConfiguracion()
{
boolean log = false;
try {
BufferedReader config = new BufferedReader(new FileReader("config.ini"));
String lin = "";
while ((lin = config.readLine()) != null)
{
if (lin.split("=").length != 1) {
String param = lin.split("=")[0].trim();
String valor = lin.split("=")[1].trim();
if (param.equalsIgnoreCase("DEBUG"))
{
if (valor.equalsIgnoreCase("true"))
{
CONFIG_DEBUG = true;
System.out.println("Modo Debug: Habilitado");
}
} else if (param.equalsIgnoreCase("LOG"))
{
if (valor.equalsIgnoreCase("true"))
{
log = true;
}
} else if (param.equalsIgnoreCase("USE_IP"))
{
if (valor.equalsIgnoreCase("true"))
{
CONFIG_USE_IP = true;
}
} else if (param.equalsIgnoreCase("SERVER_IP"))
{
IP = valor;
}
else if (param.equalsIgnoreCase("DB_HOST"))
{
HOST = valor;
} else if (param.equalsIgnoreCase("DB_USER"))
{
USUARIO = valor;
} else if (param.equalsIgnoreCase("DB_PASS"))
{
if (valor == null) valor = "";
PASSWORD = valor;
} else if (param.equalsIgnoreCase("DB_NAME"))
{
BD = valor;
} else if (param.equalsIgnoreCase("MAX_IDLE_TIME"))
{
CONFIG_MAX_IDLE_TIME = Integer.parseInt(valor) * 60000;
} else if (param.equalsIgnoreCase("CONFIG_MODO_CONSOLA"))
{
CONFIG_MODO_CONSOLA = valor.equalsIgnoreCase("true");
} else if (param.equalsIgnoreCase("LANZAR_BONUSBOX"))
{
LANZAR_BONUSBOX = Integer.parseInt(valor) * 60;
} else if (param.equalsIgnoreCase("SIZE_BONUSBOX"))
{
SIZE_BONUSBOX = Integer.parseInt(valor);
}
} }
if ((BD == null) || (HOST == null) || (PASSWORD == null) || (USUARIO == null))
{
throw new Exception();
}
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println("Fichero de configuracion inaccesible");
System.out.println("Cerrando el servidor...");
System.exit(1);
try
{
String fecha = Calendar.getInstance().get(5) + "_" + (Calendar.getInstance().get(2) + 1) + "_" + Calendar.getInstance().get(1);
if (log)
{
Log_Game = new BufferedWriter(new FileWriter("logs/" + fecha + ".txt", true));
PS = new PrintStream(new File("logs/" + fecha + "_error.txt"));
PS.append("Lanzamiento del servidor..\n");
PS.flush();
System.setErr(PS);
canLog = true;
String str = "Lanzamiento del servidor...\n";
Log_Game.write(str);
Log_Game.flush();
}
}
catch (IOException e) {
System.out.println("Los archivos de registro no se han podido crear");
System.out.println("Creando las carptetas");
new File("logs").mkdir();
System.out.println(e.getMessage());
System.exit(1);
}
}
}
public static void closeServers() {
System.out.println("Deteniendo la peticion del servidor...");
if (isRunning)
{
isRunning = false;
gameServer.kickAll();
chatServer.kickAll();
World.saveAll(null);
SQLManager.closeCons();
}
System.out.println("Detener servidor: OK");
isRunning = false;
}
}
|
|
|
07/19/2013, 12:46
|
#842
|
elite*gold: 0
Join Date: Nov 2010
Posts: 8
Received Thanks: 3
|
 ? here I've done everything but I can not connect me
|
|
|
07/19/2013, 13:16
|
#843
|
elite*gold: 0
Join Date: Mar 2012
Posts: 59
Received Thanks: 16
|
this game is online or offline?
|
|
|
07/19/2013, 13:37
|
#844
|
elite*gold: 0
Join Date: Nov 2010
Posts: 8
Received Thanks: 3
|
offline
|
|
|
07/19/2013, 13:41
|
#845
|
elite*gold: 3570
Join Date: Dec 2012
Posts: 13,044
Received Thanks: 8,252
|
Quote:
Originally Posted by darkwolf95
 ? here I've done everything but I can not connect me
|
As I told now 5000 times.
Go to navicat or phpmyadmin and edit at the table cuentas the row inventario.
Copy from the accounts above the content and insert it at your account.
Quote:
Originally Posted by Tiesto2012
this game is online or offline?
|
This is a private server package. You can make your own game with it.
Quote:
Originally Posted by darkwolf95
offline
|
|
|
|
07/19/2013, 13:53
|
#846
|
elite*gold: 0
Join Date: Aug 2010
Posts: 117
Received Thanks: 72
|
oh thought it was becouse of the class files :P thx
|
|
|
07/19/2013, 14:23
|
#847
|
elite*gold: 0
Join Date: Mar 2012
Posts: 59
Received Thanks: 16
|
how to make a hamachi so that others can connect?
or are there other ways to make a game so that the game not only for themselves but also for the other players so that they can connect?: Mofo:
|
|
|
07/19/2013, 14:31
|
#848
|
elite*gold: 3570
Join Date: Dec 2012
Posts: 13,044
Received Thanks: 8,252
|
Quote:
Originally Posted by Tiesto2012
how to make a hamachi so that others can connect?
or are there other ways to make a game so that the game not only for themselves but also for the other players so that they can connect?: Mofo:
|
Not possible with hamachi
|
|
|
07/19/2013, 14:34
|
#849
|
elite*gold: 0
Join Date: Mar 2012
Posts: 59
Received Thanks: 16
|
Quote:
Originally Posted by Requi
Not possible with hamachi
|
what then?
I want to play with my friends
|
|
|
07/19/2013, 14:37
|
#850
|
elite*gold: 3570
Join Date: Dec 2012
Posts: 13,044
Received Thanks: 8,252
|
Buy a server. There it should work
|
|
|
07/19/2013, 14:44
|
#851
|
elite*gold: 0
Join Date: Mar 2012
Posts: 59
Received Thanks: 16
|
Quote:
Originally Posted by Requi
Buy a server. There it should work 
|
in my home Wi-Fi on two computers, and I understand one IP. so I can play the server computer and the other could be connected?
sorry for my bad english
|
|
|
07/19/2013, 14:51
|
#852
|
elite*gold: 0
Join Date: Aug 2010
Posts: 117
Received Thanks: 72
|
i watched the video you made now i have the same problem before had changed the port to 90.. Stops at loading by eliaz. I dont use any ports so i didn't change it but it doesn't work
|
|
|
07/19/2013, 15:01
|
#853
|
elite*gold: 3570
Join Date: Dec 2012
Posts: 13,044
Received Thanks: 8,252
|
Quote:
Originally Posted by Ozgur-Turkmmo
i watched the video you made now i have the same problem before had changed the port to 90.. Stops at loading by eliaz. I dont use any ports so i didn't change it but it doesn't work
|
Why the f*ck are you changing the port to 90? I made it, because at my server the port 80 was blocked.
|
|
|
07/19/2013, 17:29
|
#854
|
elite*gold: 1
Join Date: Aug 2010
Posts: 1,330
Received Thanks: 1,724
|
Requi check the skype ,that program is blocking 80 at some time.
|
|
|
07/19/2013, 23:44
|
#855
|
elite*gold: 0
Join Date: Nov 2010
Posts: 8
Received Thanks: 3
|
No database selected Please help me it makes me like it eurre Post
|
|
|
All times are GMT +1. The time now is 22:25.
|
|