介紹的一些問題
我一直在嘗試,現在建立這個項目的幾個星期,並嘗試多種解決方案,我不能讓我的頭轉過身來。讓我稍微描述一下這個項目。這是一個基於文本的服務器,玩家可以登錄(通過telnet或客戶端),基本上就像一個MUD。然後,他們可以創建「對象」並與其進行交互,爲其提供「動詞」和「屬性」。關於建立網絡訪問,多用戶,可編程的,互動的環境
服務器基本上只是一個'對象'的數據庫,每個對象都有一個ID,一個名稱,一個位置(這是另一個對象),它的內容列表(對象)和其他標誌。對象可以有'動詞'和'屬性'。屬性只是存儲的數據(string,int,float,w/e)。動詞是方法/功能。對象使用諸如「放入容器中」的命令進行交互。舊版本的服務器已經存在,它被稱爲LambdaMOO。我試圖重新創建它,因爲它在很長很長的時間內沒有更新過。
你可以閱讀更深入的瞭解如何對象,動詞和性能應在工作中:http://bit.ly/17XIqjY
一個例子
讓我描述想什麼我。想象一下,我們有一個對象。對象#256,它被稱爲「按鈕」。它具有屬性「count」以及從其父項繼承的所有默認屬性(即'description')。它有一個「動詞」,稱爲「推」。這個動詞包含此代碼:
this.count += 1;
this.description = "This button has been pushed " + this.count + " times.";
player.tell("You press the button and feel a chill run down your spine.");
當服務器上的玩家類型「按鈕」,「推」動詞將運行並輸出
You press the button and feel a chill run down your spine.
如果再look
的按鈕,你會看到它的更新說明。
請注意,上述腳本中的player
指的是執行動詞的玩家的對象。 tell
是玩家對象上的另一個動詞。然而tell
動詞有一個標誌說它可以從其他動詞執行。
什麼語言?
我的主要問題是我可以使用哪些語言作爲'動詞'?我試過使用node.js和'vm'庫。我試過用C#來解析C#。我試着用C#來解析JavaScript。我一直得到的問題是我無法控制動詞和屬性的權限。如果我將它們翻譯爲JavaScript中的文字函數,我無法確定它們正在運行哪個對象以及它應具有哪些權限。如果用戶在另一個用戶對象上調用某個函數,那麼我無法攔截該調用並在權限不正確時停止該調用。我並不是完全不知道哪些語言用於動詞代碼,而只是需要將其「沙箱化」。只有當用戶設置屬性時,屬性才需要可讀/可寫,與動詞相同。我想我可以使用重載的語言(如PHP的__get,__set,__call)。
我還需要能夠注入這些變量爲動詞:(主要來自輸入的命令來確定,除非動詞正在從另一個動詞的稱呼)
player (object) the player who typed the command
this (object) the object on which this verb was found
caller (object) this will be the same as ‘player’, unless another
verb calls the command in which case it is the object
containing that verb.
verb (string) the first word of the command
argstr (string) everything after the first word of the command
args (list of strings) a list of the words in ‘argstr’
dobjstr (string) the direct object string found during parsing
dobj (object) the direct object value found during matching
prepstr (string) the prepositional phrase found during parsing
iobjstr (string) the indirect object string
iobj (object) the indirect object value
我也需要能夠從任何其他對象訪問任何對象(只要權限解決)。
// Object #128. Verb: multiply Prep: this none this Perms: +r +x
return (args[0] * args[1]);
// Object #256. Verb: square Prep: this none this Perms: +r +x
return #128:multiply(args[0], args[0]);
// Object #512. Verb: touch Prep: any any this Perms: +r
// Has a property (int) 'size' on it.
this.size = #256:square(this.size);
this.description = "It's a large button, it spans " + this.size + " metres.";
player:tell("You touch the button, it gets bigger.");
用戶然後可以push button
和按鈕對象的大小屬性將平方。
推薦閱讀
我強烈建議你在http://bit.ly/17XIqjY讀取文檔的系統應該如何工作有更深入的想法。
我們還建議您閱讀以下文檔,μMOO基於LambdaMOO,它的方法:
- https://en.wikipedia.org/wiki/LambdaMOO
- https://en.wikipedia.org/wiki/MOO
- http://www.hayseed.net/MOO/manuals/ProgrammersManual_toc.html
- http://www.moo.mud.org/
雖然我很欣賞這個問題的細節,但我建議你稍微編輯一下,以便更簡潔地理解主要問題。此外,僅供參考,有一個活躍的MOO開發社區:https://groups.google.com/forum/#!forum/moo-talk – georgek
我知道MOO Talk論壇,但該論壇非常關注原始MOO服務器和核心。這是一個基於舊的原則的全新項目。我理解這個老人的工作原理是怎樣的,我不認爲他們可以提供這方面的幫助。無論如何,我會嘗試。我也不確定是否可以在不更加模糊的情況下編輯更多的問題,但是我得到的答案不會將整個概念考慮在內。 – R4wizard
在GitHub上搜索LambdaMOO。有幾個現代的港口,你可以檢查出來。 – Brendan