Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: vito/clj-aliter
base: 4023ffc4b7
...
head fork: vito/clj-aliter
compare: 6d8aa87eed
  • 2 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
7 src/aliter/char/packets.clj
View
@@ -0,0 +1,7 @@
+(ns aliter.char.packets
+ (:use aliter.packets)
+
+ (:require [aliter.char.packets-24 :as packets-24]))
+
+(def versions
+ {24 packets-24/packets})
177 src/aliter/char/packets_24.clj
View
@@ -0,0 +1,177 @@
+(ns aliter.char.packets-24
+ (:use aliter.packets))
+
+
+(defpackets
+ [16r65 connect
+ "Character server connect request."
+ (:account-id :int)
+ (:id-a :int)
+ (:id-b :int)
+ (:client-type :short)
+ (:gender :byte)]
+
+ [16r66 choose
+ "Character selection request."
+ (:num :byte)]
+
+ [16r67 create
+ "Character creation request."
+ (:name (:string 24))
+ (:str :byte)
+ (:agi :byte)
+ (:vit :byte)
+ (:int :byte)
+ (:dex :byte)
+ (:luk :byte)
+ (:num :byte)
+ (:hair-color :short)
+ (:hair-style :short)]
+
+ [16r68 delete
+ "Character deletion request."
+ (:character-id :long)
+ (:email (:string 40))]
+
+ [16r187 keepalive
+ "Ping from client."
+ (:account-id int)]
+
+ [16r28d check-name
+ "Check if a character can be renamed."
+ (:account-id :int)
+ (:character-id :int)
+ (:new-name (:string 24))]
+
+ [16r28f rename
+ "Character rename request."
+ (:character-id :int)]
+
+
+ ; sent
+ [16r6b characters
+ "Send character list."
+ (:length :short)
+ (:max-slots :byte)
+ (:available-slots :byte)
+ (:premium-slots :byte)
+ ([] (:byte 20))
+ (:characters [(:id :int)
+ (:base-experience :int)
+ (:zeny :int)
+ (:job-experience :int)
+ (:job-level :int)
+ (0 :int) ; body state
+ (0 :int) ; health state
+ (:effects :int)
+ (:karma :int)
+ (:manner :int)
+ (:status-points :short)
+ (:hp :int)
+ (:max-hp :int)
+ (:sp :short)
+ (:max-sp :short)
+ (150 :short) ; walk speed
+ (:job :short)
+ (:hair-style :short)
+ (:view-weapon :short)
+ (:base-level :short)
+ (:skill-points :short)
+ (:view-head-bottom :short)
+ (:view-shield :short)
+ (:view-head-top :short)
+ (:view-head-middle :short)
+ (:hair-color :short)
+ (:clothes-color :short)
+ (:name (:string 24))
+ (:str :byte)
+ (:agi :byte)
+ (:vit :byte)
+ (:int :byte)
+ (:dex :byte)
+ (:luk :byte)
+ (:num :short)
+ (1 :short) ; 0 for renamed?
+ (:map (:string 16))
+ (0 :int) ; delete date
+ (0 :int) ; robe
+ ;(0 :int) ; change slot (0 = disabled)
+ ;(0 :int) ; unknown (0 = disabled)
+ ])]
+
+ [16r6c refuse
+ "Refuse connection."
+ (:reason :byte)]
+
+ [16r6d character-created
+ "Character successfully created."
+ (:id :int)
+ (:base-experience :int)
+ (:zeny :int)
+ (:job-experience :int)
+ (:job-level :int)
+ (0 :int) ; body state
+ (0 :int) ; health state
+ (:effects :int)
+ (:karma :int)
+ (:manner :int)
+ (:status-points :short)
+ (:hp :int)
+ (:max-hp :int)
+ (:sp :short)
+ (:max-sp :short)
+ (150 :short) ; walk speed
+ (:job :short)
+ (:hair-style :short)
+ (:view-weapon :short)
+ (:base-level :short)
+ (:skill-points :short)
+ (:view-head-bottom :short)
+ (:view-shield :short)
+ (:view-head-top :short)
+ (:view-head-middle :short)
+ (:hair-color :short)
+ (:clothes-color :short)
+ (:name (:string 24))
+ (:str :byte)
+ (:agi :byte)
+ (:vit :byte)
+ (:int :byte)
+ (:dex :byte)
+ (:luk :byte)
+ (:num :short)
+ (1 :short)] ; 0 for renamed?
+
+ [16r6e creation-failed
+ "Character creation failed."
+ (:reason :byte)]
+
+ [16r6f character-deleted
+ "Character deleted."]
+
+ [16r70 deletion-failed
+ "Character deletion failed."
+ (:reason :byte)]
+
+ [16r71 switch-to-zone
+ "Switch to zone server after choosing character."
+ (:character-id :int)
+ (:map (:string 16))
+ (:ip (:byte 4))
+ (:port :short)]
+
+ [16r28e name-check-result
+ "Is a character renameable?"
+ (:reason :short)]
+
+ [16r290 rename-result
+ "Rename request result."
+ (:reason :short)]
+
+ [16r889 pin-code
+ "?"
+ (0 :short)
+ (0 :short)
+ (:account-id :int)
+ (0 :short)]
+ )
4 src/aliter/core.clj
View
@@ -1,7 +1,9 @@
(ns aliter.core
(:require [clojure.tools.nrepl.server :as nrepl]
- [aliter.server.login :as login]))
+ [aliter.server.login :as login]
+ [aliter.server.char :as char]))
(defn -main []
(future (login/start 6900))
+ (future (char/start 5121))
(nrepl/start-server :port 7888))
13 src/aliter/data.clj
View
@@ -2,3 +2,16 @@
(defrecord Account
[id login password email gender last-login last-ip])
+
+(defrecord Char
+ [id account-id num name
+ job base-level base-experience job-level job-experience
+ zeny str agi vit int dex luk
+ max-hp hp max-sp sp
+ status-points skill-points
+ hair-style hair-color clothes-color
+ view-weapon view-shield view-head-top view-head-middle view-head-bottom
+ map x y save-map save-x save-y
+ renamed effects karma manner fame
+ party-id guild-id guild-position guild-taxed
+ pet-id homunculus-id mercenary-id])
155 src/aliter/db.clj
View
@@ -1,8 +1,8 @@
(ns aliter.db
(:require [aliter.data :as data])
(:require [redis.core :as redis])
-
- (:import [aliter.data Account]))
+
+ (:import [aliter.data Account Char]))
(defmacro with-db [& body]
`(redis/with-server {}
@@ -15,12 +15,13 @@
(:id account)
(redis/incr "accounts:id"))
acc (str "account:" id)]
- (redis/hset acc "login" (:login account))
- (redis/hset acc "password" (:password account))
- (redis/hset acc "email" (:email account))
- (redis/hset acc "gender" (:gender account))
- (redis/hset acc "last-login" (:last-login account))
- (redis/hset acc "last-ip" (:last-ip account))
+ (redis/hmset acc
+ "login" (:login account)
+ "password" (:password account)
+ "email" (:email account)
+ "gender" (:gender account)
+ "last-login" (:last-login account)
+ "last-ip" (:last-ip account))
(redis/hset (str "account:" (:login account)) id)))
@@ -42,3 +43,141 @@
(let [id (redis/get (str "account:" login))]
(when id
(Integer/parseInt id))))
+
+
+(defn save-character [character]
+ (redis/atomically
+ (let [id (if (:id character)
+ (:id character)
+ (redis/incr "characters:id"))
+ chr (str "character:" id)]
+ (redis/hmset chr
+ "id" (:id character)
+ "account-id" (:account-id character)
+ "num" (:num character)
+ "name" (:name character)
+ "job" (:job character)
+ "base-level" (:base-level character)
+ "base-experience" (:base-experience character)
+ "job-level" (:job-level character)
+ "job-experience" (:job-experience character)
+ "zeny" (:zeny character)
+ "str" (:str character)
+ "agi" (:agi character)
+ "vit" (:vit character)
+ "int" (:int character)
+ "dex" (:dex character)
+ "luk" (:luk character)
+ "max-hp" (:max-hp character)
+ "hp" (:hp character)
+ "max-sp" (:max-sp character)
+ "sp" (:sp character)
+ "status-points" (:status-points character)
+ "skill-points" (:skill-points character)
+ "hair-style" (:hair-style character)
+ "hair-color" (:hair-color character)
+ "clothes-color" (:clothes-color character)
+ "view-weapon" (:view-weapon character)
+ "view-shield" (:view-shield character)
+ "view-head-top" (:view-head-top character)
+ "view-head-middle" (:view-head-middle character)
+ "view-head-bottom" (:view-head-bottom character)
+ "map" (:map character)
+ "x" (:x character)
+ "y" (:y character)
+ "save-map" (:save-map character)
+ "save-x" (:save-x character)
+ "save-y" (:save-y character)
+ "renamed" (:renamed character)
+ "effects" (:effects character)
+ "karma" (:karma character)
+ "manner" (:manner character)
+ "fame" (:fame character)
+ "party-id" (:party-id character)
+ "guild-id" (:guild-id character)
+ "guild-position" (:guild-position character)
+ "guild-taxed" (:guild-taxed character)
+ "pet-id" (:pet-id character)
+ "homunculus-id" (:homunculus-id character)
+ "mercenary-id" (:mercenary-id character))
+
+ (redis/hset (str "character:" (:name character)) id)))
+
+ character)
+
+(defn get-character [id]
+ (let [attrs (redis/hgetall (str "character:" id))]
+ (when attrs
+ (Char.
+ (Integer/parseInt (attrs "id"))
+ (Integer/parseInt (attrs "account-id"))
+ (Integer/parseInt (attrs "num"))
+ (attrs "name")
+ (Integer/parseInt (attrs "job"))
+ (Integer/parseInt (attrs "base-level"))
+ (Integer/parseInt (attrs "base-experience"))
+ (Integer/parseInt (attrs "job-level"))
+ (Integer/parseInt (attrs "job-experience"))
+ (Integer/parseInt (attrs "zeny"))
+ (Integer/parseInt (attrs "str"))
+ (Integer/parseInt (attrs "agi"))
+ (Integer/parseInt (attrs "vit"))
+ (Integer/parseInt (attrs "int"))
+ (Integer/parseInt (attrs "dex"))
+ (Integer/parseInt (attrs "luk"))
+ (Integer/parseInt (attrs "max-hp"))
+ (Integer/parseInt (attrs "hp"))
+ (Integer/parseInt (attrs "max-sp"))
+ (Integer/parseInt (attrs "sp"))
+ (Integer/parseInt (attrs "status-points"))
+ (Integer/parseInt (attrs "skill-points"))
+ (Integer/parseInt (attrs "hair-style"))
+ (Integer/parseInt (attrs "hair-color"))
+ (Integer/parseInt (attrs "clothes-color"))
+ (Integer/parseInt (attrs "view-weapon"))
+ (Integer/parseInt (attrs "view-shield"))
+ (Integer/parseInt (attrs "view-head-top"))
+ (Integer/parseInt (attrs "view-head-middle"))
+ (Integer/parseInt (attrs "view-head-bottom"))
+ (attrs "map")
+ (Integer/parseInt (attrs "x"))
+ (Integer/parseInt (attrs "y"))
+ (attrs "save-map")
+ (Integer/parseInt (attrs "save-x"))
+ (Integer/parseInt (attrs "save-y"))
+ (Integer/parseInt (attrs "renamed"))
+ (Integer/parseInt (attrs "effects"))
+ (Integer/parseInt (attrs "karma"))
+ (Integer/parseInt (attrs "manner"))
+ (Integer/parseInt (attrs "fame"))
+ (Integer/parseInt (attrs "party-id"))
+ (Integer/parseInt (attrs "guild-id"))
+ (Integer/parseInt (attrs "guild-position"))
+ (Integer/parseInt (attrs "guild-taxed"))
+ (Integer/parseInt (attrs "pet-id"))
+ (Integer/parseInt (attrs "homunculus-id"))
+ (Integer/parseInt (attrs "mercenary-id"))))))
+
+(defn get-account-characters [id]
+ (let [chars (redis/hgetall (str "account:" id ":chars"))]
+ (map #(get-character (fnext %)) chars)))
+
+(defn get-account-character [id num]
+ (let [idx (str num)
+ chars (redis/hgetall (str "account:" id ":chars"))]
+ (when (contains? chars idx)
+ (get-character (chars idx)))))
+
+(defn get-character-id [name]
+ (let [id (redis/get (str "character:" name))]
+ (when id
+ (Integer/parseInt id))))
+
+(defn rename-character [id old-name new-name]
+ (let [chr (str "char:" id)]
+ (redis/atomically
+ (redis/del (str "char:" old-name))
+ (redis/set (str "char:" new-name) id)
+ (redis/hset chr "name" new-name)
+ (redis/hset chr "renamed" 1)
+ true)))
17 src/aliter/server/char.clj
View
@@ -0,0 +1,17 @@
+(ns aliter.server.char
+ (:use aliter.packets
+ aliter.db)
+ (:require [aliter.char.packets :as packets]
+ [aliter.packet-server :as server]))
+
+(defrecord CharState [packets]
+ server/PacketHandler
+ (packets [this] packets)
+
+ (handle [this packet body respond]
+ (println "got packet" body)
+ this))
+
+(defn start [port]
+ (with-db
+ (server/run (CharState. (packets/versions 24)) port)))

No commit comments for this range

Something went wrong with that request. Please try again.